Close an open XML element tag, programmatically in java -


this question has answer here:

i have xml string response server open tags, like: example:

<address1><street>this caused error coz street not closed</address1> <address2>this displayed normal</address2> 

while parsing above xml string, got, org.xml.sax.saxparseexception: element type "street" must gathered.

note: can't change server files.

first, not think should work invalid xml because lead unpredictable results. best update server files have valid xml content.

that being said, can use jsoup html parser can manage such invalid xml.

for provided example:

string xml = "<address1><street>this caused error coz street not closed</address1><address2>this displayed normal</address2>"; document doc = jsoup.parse(xml, "", parser.xmlparser()); elements elements = doc.getelementsbytag("address1"); system.out.println(elements.first().text()); // print: "this caused error coz street not closed" elements elements2 = doc.getelementsbytag("address2"); system.out.println(elements2.first().text()); // print: "this displayed normal" 

the street element ignored.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -