5

Is it possible to parse the XML files from SAX parser without defining the tags name in Java file? I want to make my code generic so that it can parse any kind of XML file rather than some specific XML files.

3
  • 3
    A SAX Parser is a generic XML parser already. What do you really want to do? Commented May 26, 2012 at 16:50
  • Yes, of course it's possible. However, it rather depends on what you want your application to do with the output from the SAX parser. Commented May 27, 2012 at 18:45
  • What solution are you using to parse xml? Commented Feb 8, 2018 at 10:06

2 Answers 2

3

It sounds like you are looking for XML-to-Object "parser" with externalized mapping (e.g. XML, annotations) or an implied convention. Here's a list to chose from:

you will sure find more. If you would rather parse your XML by hand using SAX (or DOM, or StAX) then you have to know the names of the XML tags you are interested in. You can abstract them out and make your parser configuration driven but if you are constructing objects from your XML data then your time is better spent picking a framework that can do it for you

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Pravel Veller for the answer.
0

Yes, it is. Have a look at JDOM, DOM4J and XOM. They are all parsing XML through SAX and building a tree a of nodes. However, it is unclear what you mean by "without defining the tags name in Java file".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.