learningtocode
learningtocode

Reputation: 765

Is there a way I can read a xml file in java without having to define the class to read into

I am experimenting with JAXB library to read xml files and I see that I need to define the Class objects along with annotations to indicate the xml element structure. I was wondering if there is a way that I can read the xml file without having to define such a class. this will permit the user to add a new tag without having to redefine my class.

I am not particular about jaxb usage, any other java libraries are ok too.

Upvotes: 1

Views: 161

Answers (1)

Affe
Affe

Reputation: 47994

Sure, if you just want to work with raw XML without binding it onto POJOs, you can use javax.xml.parsers.DocumentBuilderFactory/javax.xml.parsers.DocumentBuilder to read any arbitrary XML directly into a org.w3c.dom.Document and just work with it as a document instead of as mapped data.

Upvotes: 6

Related Questions