muttley73 / jlibs

Automatically exported from code.google.com/p/jlibs
0 stars 0 forks source link

XML element without closing tag is parsed successfully #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to parse XML without closing tag (like "<root>").
It is parsed successfully but shouldn't be.

What is the expected output? What do you see instead?
Expected:
  A new exception like XPathException or some other should be raised.
Actual:
  No exception is raised

What version of the product are you using? On what operating system?
Version: 1.0-SNAPSHOT
OS: Win XP

Original issue reported on code.google.com by surko...@gmail.com on 24 Jan 2012 at 9:12

GoogleCodeExporter commented 9 years ago
can u give details of the piece of code you are using.

i mean are you using XMLDog or AsyncXMLReader....

Original comment by santhosh.tekuri@gmail.com on 25 Jan 2012 at 12:52

GoogleCodeExporter commented 9 years ago
If your xpath gets hit before reaching the invalid region of xml, then XMLDog 
doesn't throw exception.

XMLDog stops reading xml file once all xpaths given are evaluated.

Original comment by santhosh.tekuri@gmail.com on 25 Jan 2012 at 12:57

GoogleCodeExporter commented 9 years ago
I'm using XMLDog.
This is a piece of code:

            StringReader reader = new StringReader(message.getText());
            DefaultNamespaceContext nsContext = new DefaultNamespaceContext();
            XMLDog XML_DOG = new XMLDog(nsContext, null, null);
            XPathResults results = XML_DOG.sniff(new             InputSource(reader));
            List<NodeItem> resultList = (List<NodeItem>) results.getResult(XML_DOG.addXPath("/XPATH"));

If input XML message is equal to  "<root>" (element name without closing tag) 
then "sniff" method doesn't throw any exception.

Original comment by surko...@gmail.com on 13 Feb 2012 at 12:35

GoogleCodeExporter commented 9 years ago
sniff method should be called after adding xpaths. but in your code sniff is 
called first and then you are adding xpath. the correct code is:

            StringReader reader = new StringReader(message.getText());
            DefaultNamespaceContext nsContext = new DefaultNamespaceContext();
            XMLDog XML_DOG = new XMLDog(nsContext, null, null);
            Expression xpath = XML_DOG.addXPath("/XPATH");
            XPathResults results = XML_DOG.sniff(new InputSource(reader));
            List<NodeItem> resultList = (List<NodeItem>) results.getResult(xpath); 

Original comment by santhosh.tekuri@gmail.com on 13 Feb 2012 at 1:50