I want to read an XML file into memory as a tree of nodes, on which I could perform further operations. Something like C#'s XDocument. What is the Java equivalent of C#'s XDocument.Load?
Asked
Active
Viewed 2,031 times
1
Joel C
- 5,547
- 1
- 21
- 31
Eccemelophile
- 11
- 2
-
Are you asking about `XDocument` or `XmlDocument`? `XDocument` is part of LINQ to XML, so you're probably not going to find any Java equivalent, as LINQ only exists in .NET – Joel C Jun 05 '11 at 04:48
-
See http://stackoverflow.com/questions/6159047/modern-alternative-to-java-xstream-library for some Java XML libraries. There may be something there that fits your way of working better than plain DOM. Also, Simple (http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#deserialize) seems to be, well, simple to use. – extraneon Jun 05 '11 at 08:44
1 Answers
6
You're looking for the Java XML DOM classes, which are part of JAXP. It's much uglier than in C#.
- A
DocumentBuilderFactorycreates... - A
DocumentBuilderwhich creates... - A
Documentwhich is what you're really after.
An excellent reference for all this: the JAXP Tutorial, Chapter 3: The Document Object Model.
Matt Ball
- 354,903
- 100
- 647
- 710