Skip to content

XML.toJSONObject - xml content trimmed #695

@ilmagowalter

Description

@ilmagowalter

when create a JSONObject from XML String like

<?xml version="1.0" encoding="utf-8"?><tagA> : </tagA>

spaces at then begin and at the end of string are trimmed

	public static void main(String[] args) {
		String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><tagA>  :</tagA>";
		JSONObject jo = XML.toJSONObject(xml, true);
		System.out.println("Test 1");
		System.out.println(jo.toString());

		xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><tagA>  :  </tagA>";
		jo = XML.toJSONObject(xml, true);
		System.out.println("Test 2");
		System.out.println(jo.toString());

		xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><tagA>:  </tagA>";
		jo = XML.toJSONObject(xml, true);
		System.out.println("Test 3");
		System.out.println(jo.toString());
	}

output

Test 1
{"tagA":":"}
Test 2
{"tagA":":"}
Test 3
{"tagA":":"}

is possible add a parameter to avoid trimming ?

i think that method involved is nextContent() of XMLTokener.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions