0

In a java app that I am working on, there is a need to take an existing XML, then make changes to that xml and give the original as well as new xml, as output.

Which parser do you recommend, such that it uses least memory? Where I can do the following--

(a) easily take one portion of the xml, and insert it into another place in the same XML?

(b) change some attributes in a section of the xml.

Arvind
  • 6,404
  • 20
  • 94
  • 143

2 Answers2

1

If the document is huge you can take a look at SAX, otherwise just use a DOM parser like dom4j for exemple.

With any DOM parser you can copy a node and attach it elsewhere in the document tree.

For exemple using dom4j you can use Element.createCopy to copy an element, and add it elsewhere.

Alex
  • 25,147
  • 6
  • 59
  • 55
  • But surely as stated in the comments upper, if you can avoid Java, then use XSLT for such a task – Alex Jun 11 '12 at 09:27
0

Here's a huge list of Java Parsers for you to choose from. Most of them have the capability to do what you need - XML Parsing, Selecting/Filtering/Copying/Moving Nodes, Modifying Attributes, XML File Read/Write Capabilities, etc. Each has its own advantages disadvantages - the main choosing criteria being Speed and Performance:

JDOM
XMLBeans
Xerces
Apache Betwixt
XStream
StAX
JAXB
XP Parser
kXML
JiBX: Binding XML to Java Code
woodstox
VTD-XML 1.5
Zeus
Skaringa
Lycia
Piccolo XML Parser
NanoXML
NekoPull
XOM
dom4j
Jakarta Commons Digester
JOX
KBML
X2JB
Staxmate

Ref1: http://java-source.net/open-source/xml-parsers

Ref2: Best XML parser for Java

Community
  • 1
  • 1
Ashok Goli
  • 5,043
  • 8
  • 38
  • 68
  • I am looking for a parser that uses least memory- processing time is not so much a factor but memory usage is most important- which ones do you suggest for my scenario? Thanks... – Arvind Jun 11 '12 at 10:03