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. @retu
(XMLTokener x, boolean arrayForm, JSONArray ja)
| 41 | * @return A JSONArray if the value is the outermost tag, otherwise null. |
| 42 | */ |
| 43 | private static Object parse(XMLTokener x, boolean arrayForm, JSONArray ja) throws JSONException { |
| 44 | String attribute; |
| 45 | char c; |
| 46 | String closeTag = null; |
| 47 | int i; |
| 48 | JSONArray newja = null; |
| 49 | JSONObject newjo = null; |
| 50 | Object token; |
| 51 | String tagName = null; |
| 52 | |
| 53 | // Test for and skip past these forms: |
| 54 | // <!-- ... --> |
| 55 | // <![ ... ]]> |
| 56 | // <! ... > |
| 57 | // <? ... ?> |
| 58 | |
| 59 | while (true) { |
| 60 | if (!x.more()) { |
| 61 | throw x.syntaxError("Bad XML"); |
| 62 | } |
| 63 | token = x.nextContent(); |
| 64 | if (token == XML.LT) { |
| 65 | token = x.nextToken(); |
| 66 | if (token instanceof Character) { |
| 67 | if (token == XML.SLASH) { |
| 68 | |
| 69 | // Close tag </ |
| 70 | |
| 71 | token = x.nextToken(); |
| 72 | if (!(token instanceof String)) { |
| 73 | throw new JSONException("Expected a closing name instead of '" + token + "'."); |
| 74 | } |
| 75 | if (x.nextToken() != XML.GT) { |
| 76 | throw x.syntaxError("Misshaped close tag"); |
| 77 | } |
| 78 | return token; |
| 79 | } else if (token == XML.BANG) { |
| 80 | |
| 81 | // <! |
| 82 | |
| 83 | c = x.next(); |
| 84 | if (c == '-') { |
| 85 | if (x.next() == '-') { |
| 86 | x.skipPast("-->"); |
| 87 | } else { |
| 88 | x.back(); |
| 89 | } |
| 90 | } else if (c == '[') { |
| 91 | token = x.nextToken(); |
| 92 | if (token.equals("CDATA") && x.next() == '[') { |
| 93 | if (ja != null) { |
| 94 | ja.put(x.nextCDATA()); |
| 95 | } |
| 96 | } else { |
| 97 | throw x.syntaxError("Expected 'CDATA['"); |
| 98 | } |
| 99 | } else { |
| 100 | i = 1; |
no test coverage detected