You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Shekhar Jha <sh...@usa.net> on 2002/10/01 03:01:11 UTC

XPath to generate XML

I am thinking along the lines of generating a skeleton DOM
using the path i.e. along the line of 
instead of writing a code like
...
Element element = document.createElement("Order"));
document.appendChild(element);
Node node = XPathAPI.selectSingleNode("/Order");
node.appendChild( document.createElement("Customer" ) );
Node node = XPathAPI.selectSingleNode("/Order/Customer[1]");
node.appendChild( document.createElement("Name" ) );
Node node = XPathAPI.selectSingleNode("/Order/Customer[1]/Name");
node.appendChild(document.createText("John Doe") );
....

I would like to just do
... 
Node node = XPathAPI.selectSingleNode("/Order/Customer[1]/Name");
node.appendChild(document.createText("John Doe") );
....

Does this make sense? I am banking on the fact that XPath implementation would
have a tree of some sort that I can traverse to generate the DOM.
I am not a XML expert and am NOT sure whether what I am looking for is valid
in XML world!!
Thanks for all your help
Shekhar Jha