not strict xpath for java

do you know any not strict xpath for java? (I want it to not check dtd and schema) and it would be cool if it dont care about correct xml.

Asked by: Arthur241 | Posted: 23-01-2022

Answer 1

You don't need to schema valid XML to use XPath. For non-well-formed XML, then I think you have two options:

  • generate a valid DOM tree from the file. Suggest sucking the file through JTidy or TagSoup. Once you have that, you can use XPath as normal.
  • generate some other tree shaped model, then use a customized Navigator for Jaxen's XPath. (Jaxen lets you use XPath on any model you want).

Answered by: Jack819 | Posted: 24-02-2022

Answer 2

Ok, first of all, "correct xml" can be interpreted in a couple of ways. If you mean "non-well-formed" (missing angle brackets, overlapping elements, etc.), no version of xpath would likely do anything useful with that. You'd be better off with some sort of regular expressions. If your XML isn't well-formed, I hope you have some clue of how it won't be well-formed, otherwise you have no hope of getting anywhere with it.

If you actually mean "invalid", which simply means it doesn't validate against a schema or DTD, then you can use predicates which compare against the "local-name()" function. For instance, if you want to find the "/foo/bar" element, ignoring schemas, then your xpath would look like this:


Answered by: Aston139 | Posted: 24-02-2022

Similar questions

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)