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

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -