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.

2
  • 3
    Have you considered XSLT processing with apache xalan? Commented Jun 11, 2012 at 9:23
  • XSLT is intended for what you describe. Java is a general-purpose language. XSLT will be MUCH easier, and you can even invoke the XSL from Java. Commented Jun 11, 2012 at 9:26

2 Answers 2

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.

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

1 Comment

But surely as stated in the comments upper, if you can avoid Java, then use XSLT for such a task
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

1 Comment

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...

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.