I don't think there are any Xerces samples that
demonstrate editing the DOM tree, but the process is straightforward. Find a
node that you want to modify, then use create..() functions (createElement(),
createTextNode(), etc) to create any new nodes and append...() or
replace...() functions (appendChild(), replaceChild() etc) to append them to the
parent or replace existing nodes. You can also remove nodes (removeChild()) and
add or remove attributes.
The CreateDOMDocument sample demonstrates the process
of creating and appending nodes. See the API docs on the Xerces-C site and the
DOM spec on the W3C site (and/or a good book on the DOM) for more
information.
Bear in mind that XSLT is designed for
precisely this purpose. The W3C site calls it "a language
for transforming XML." You may be able to accomplish what you need by writing
one or more stylesheets instead of code, and you'll have all the power and
flexibility of XSLT available to meet future demands on your system. It might
not perform as well as carefully purpose-built code, though. Using XSLT would
also give you a degree of platform independence. (For instance, modern XSLT
processors in Java can generate efficient classes to implement any given
transform that will run anywhere there's a Java virtual
machine.)
Please be sure to send your messages to the Xerces
mailing list, not just to my address. A lot of smart, experienced people read
the traffic, and may have more useful and/or accurate advice to offer.
Furthermore, the answers to your questions will be archived for the benefit of
those who have similar questions later.
From: premkumar srinivasan [mailto:[EMAIL PROTECTED]
Sent: Monday, October 17, 2005 10:12 AM
To: Jesse Pelton
Subject: Re: XML Dom parsers and updators.Hi Jesse,There was some minor issue, and now, I could execute xgrep, without having any problem.I was thinking about using Xerces API for accessing the DOM Tree, as you suggested. Will you please guide me to any known sample classic documentation, that talks on updating XML using Xerces API.Thanks a lot!--Prem.
On 10/17/05, premkumar srinivasan <[EMAIL PROTECTED]> wrote:On installing, and running xgrep ( as is, from http://software.decisionsoft.com/pathanXgrepDocumentation.html ) , I am getting the following error:E:\pathanGrepX\Debug>pathanGrepX -v "/descendant::orderNumber" test.xmlError at file "00604C90", line 2, column 12
Message: 00604C28
Error during script parsing, in file test.xml at line 2, column 12.
Message: 00604CF8
Cannot open file test.xml.test.xml file contents:<?xml version="1.0" encoding="utf-8"?>
<purchases><orderNumber id="PA1" /><group>
<orderNumber id="PA2" />
</group>
</purchases>Am I missing anything ???Thanks for pointing at Xalan. I have already installed Xalan.Thanks,--Prem.
On 10/13/05, Jesse Pelton <[EMAIL PROTECTED]> wrote:Xgrep is a nifty tool. It's a great way to explore XPath and to develop and hone expressions.The DOM specification (which Xerces attempts to implement faithfully) includes methods for modifying the tree. However, I'm beginning to wonder if you're looking for more command-line tools like Xgrep to perform your modifications for you. If so, Xerces alone won't help, because it's a library that implements an API. It doesn't include any programs to make arbitrary modifications to the input.If you want a command-line tool to do XML-aware document transformation, you'll need something that allows you to specify the transformation (a template or stylesheet) to be performed along with the input document. If this is the case, you should look at XSLT, Velocity, etc. For instance, Xalan-C includes a command-line processor (called, appropriately, Xalan) that takes an XML source document and an XSLT stylesheet and outputs the result of applying the stylesheet to the document.
From: premkumar srinivasan [mailto:[EMAIL PROTECTED] ]
Sent: Thursday, October 13, 2005 10:24 AM
To: Jesse Pelton
Subject: Re: XML Dom parsers and updators.
Hi,Thanks for pointing at Pathan.I have installed xerces version 2.3 and pathan version 2. I think, the xgrep program ( http://software.decisionsoft.com/pathanXgrepDocumentation.html), can be used for XPATH. Right????Also, for modifying the DOMTree, can xerces API libraries for DOM files be used for updating the XML file ( which is been represented in the memory as a DOM Tree )? Is there anything that can be used along with XERCES and PATHAN, to update the DOM Tree.Am I going in the right direction?Thanks,--Prem,
On 10/11/05, Jesse Pelton <[EMAIL PROTECTED]> wrote:There are any number of template-based transformers, some of which use DOM and XPath as you're describing, some of which don't. Projects with their own template systems include Velocity and FreeMarker (both Java) among others. The standardized XML transformation language is XSLT, which is implemented in Apache's Xalan (C++ or Java), Gnome's libxml2/gdome2/libxslt, and quite a few other libraries.If you want your updates to be driven by code rather than templates, any of these libraries should serve, or you can use Xerces-C for the DOM and Pathan (which is built on Xerces) for XPath.
From: premkumar srinivasan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 11, 2005 11:23 AM
To: [email protected]
Subject: Reg: XML Dom parsers and updators.
Hi,
Is there any open source based on XML, that allows us to do the following:
- Parse XML into a DOM Tree.
- Retrieve the XML data using XPATH queries.
- Update the DOM Tree, based on the update-type. It might be DOM node updation, or addition of a new DOM node sets.It's something like making XML file, a database, and use "SQL" sort of queries to update/retrieve data.
Your suggestions would be really helpful for me.
Thanks,
--Prem
