Building a XML file thanks to a XPath-like syntax

R

redcic

Hi all,

I would like to build a xml file using Xerces. I know how to build a
single node at a time.
For example, with 'doc' belonging to the DocumentImpl class and with
'docRootNode' belonging to the ElementNSImpl class, I do:

myElement = doc.createElement('elementName')
docRootNode.appendChild(myElement)

However, what I would like to be able to do is to use a XPath-like
syntax to build my xml file. Something of the type:

myElement = doc.createElement('parentName/elementName')

where on can recognize a XPath syntax in 'parentName/elementName'.

Is there a way to do so ?
What class of Xerces allows me to do that ?

Thanks a lot for your help,

Cédric
 
J

Joseph Kesselman

As far as I know, there's no standard, or even common, tool which will
implicitly create intermediate elements. You get to invent it yourself.
 
R

roy axenov

I would like to build a xml file using Xerces. I know how
to build a single node at a time.
However, what I would like to be able to do is to use a
XPath-like syntax to build my xml file. Something of the
type:

myElement = doc.createElement('parentName/elementName')

That sounds like a rather bad idea to me. Why invent a
primitive, non-standard language, easily confused with
XPath, which *is* standard but addresses a wholly different
problem domain (to quote from the spec: 'XPath is a
language for addressing parts of an XML document'), and
incurring a penalty for parsing that language run-time?

Especially since a standard language for serializing XML
DOM Documents and XML DOM Document Fragments as plain text
already exists. Hint: it's called XML.
where on can recognize a XPath syntax in
'parentName/elementName'.

Like that's a good thing. How do you add attributes or text
nodes? What if someone experiences a braino and attempts to
stuff a predicate in your 'XPath' expression?
What class of Xerces allows me to do that ?

What gave you an idea a class like that would exist?

Either use XML (and suffer run-time performance penalty for
parsing it) or stuff all the elements you need created into
a container and iterate until blue in the face. This
'XPath' thingo you came up with combines the worst of both
worlds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top