Building a XML file thanks to a XPath-like syntax

Discussion in 'XML' started by redcic, Mar 2, 2007.

  1. redcic

    redcic Guest

    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
    redcic, Mar 2, 2007
    #1
    1. Advertising

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

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 2, 2007
    #2
    1. Advertising

  3. redcic

    roy axenov Guest

    On Mar 2, 4:58 pm, "redcic" <>
    wrote:
    > 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.

    --
    roy axenov
    roy axenov, Mar 2, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,939
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,356
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    499
  4. Patrick Kowalzick
    Replies:
    5
    Views:
    453
    Patrick Kowalzick
    Mar 14, 2006
  5. Luke Galea

    Xpath like syntax

    Luke Galea, Jan 21, 2005, in forum: Ruby
    Replies:
    12
    Views:
    243
    Luke Galea
    Jan 22, 2005
Loading...

Share This Page