Parse XML values and store them in a JSONArray. @param x The XMLTokener containing the source string. @param arrayForm true if array form, false if object form. @param ja The JSONArray that is containing the current tag or null if we are at the outermost level. @return A JSONArray if
(XMLTokener x, boolean arrayForm,
JSONArray ja)
| 46 | * @throws JSONException |
| 47 | */ |
| 48 | private static Object parse(XMLTokener x, boolean arrayForm, |
| 49 | JSONArray ja) throws JSONException { |
| 50 | String attribute; |
| 51 | char c; |
| 52 | String closeTag = null; |
| 53 | int i; |
| 54 | JSONArray newja = null; |
| 55 | JSONObject newjo = null; |
| 56 | Object token; |
| 57 | String tagName = null; |
| 58 | |
| 59 | // Test for and skip past these forms: |
| 60 | // <!-- ... --> |
| 61 | // <![ ... ]]> |
| 62 | // <! ... > |
| 63 | // <? ... ?> |
| 64 | |
| 65 | while (true) { |
| 66 | token = x.nextContent(); |
| 67 | if (token == XML.LT) { |
| 68 | token = x.nextToken(); |
| 69 | if (token instanceof Character) { |
| 70 | if (token == XML.SLASH) { |
| 71 | |
| 72 | // Close tag </ |
| 73 | |
| 74 | token = x.nextToken(); |
| 75 | if (!(token instanceof String)) { |
| 76 | throw new JSONException( |
| 77 | "Expected a closing name instead of '" + |
| 78 | token + "'."); |
| 79 | } |
| 80 | if (x.nextToken() != XML.GT) { |
| 81 | throw x.syntaxError("Misshaped close tag"); |
| 82 | } |
| 83 | return token; |
| 84 | } else if (token == XML.BANG) { |
| 85 | |
| 86 | // <! |
| 87 | |
| 88 | c = x.next(); |
| 89 | if (c == '-') { |
| 90 | if (x.next() == '-') { |
| 91 | x.skipPast("-->"); |
| 92 | } |
| 93 | x.back(); |
| 94 | } else if (c == '[') { |
| 95 | token = x.nextToken(); |
| 96 | if (token.equals("CDATA") && x.next() == '[') { |
| 97 | if (ja != null) { |
| 98 | ja.put(x.nextCDATA()); |
| 99 | } |
| 100 | } else { |
| 101 | throw x.syntaxError("Expected 'CDATA['"); |
| 102 | } |
| 103 | } else { |
| 104 | i = 1; |
| 105 | do { |
no test coverage detected