Alternative to GetElementById

Discussion in 'XML' started by Billy, Sep 27, 2005.

  1. Billy

    Billy Guest

    I wish to select a node using the value of one of its attributes, i.e.

    xml:
    ....
    <tablelist>
    <table name="table1">
    ...
    </table>
    <table name="table2">
    ...
    </table>
    ...
    </tablelist>
    ....

    Method Call: element = xmlDoc.GetElementById("table1")

    But from what I have been reading and tested this only works if I am
    using DTD and the attribute is of type ID. I don't want to use a DTD
    (already using XSD) so how can I either use this method or is there an
    alternative that doesn't tie me to using DTD's?
    Note, I know I can select all of the nodes in the <tablelist> node and
    then loop but I would rather not as this list could be huge.

    Thanks

    Billy
    Billy, Sep 27, 2005
    #1
    1. Advertising

  2. Billy wrote:

    > I wish to select a node using the value of one of its attributes, i.e.
    >
    > xml:
    > ...
    > <tablelist>
    > <table name="table1">
    > ...
    > </table>
    > <table name="table2">
    > ...
    > </table>
    > ...
    > </tablelist>
    > ...
    >
    > Method Call: element = xmlDoc.GetElementById("table1")
    >
    > But from what I have been reading and tested this only works if I am
    > using DTD and the attribute is of type ID. I don't want to use a DTD
    > (already using XSD) so how can I either use this method or is there an
    > alternative that doesn't tie me to using DTD's?


    Depending on the DOM implementation/API you use it might for instance be
    possible to use an XPath expression e.g.
    /tablelist/table[@name = 'table1']
    to look for that element.
    But you haven't told us anything on what DOM implementation you use so I
    can't tell whether XPath is possible for you or not.

    It might also suffice if your XSD declares the name attribute of <table>
    elements to be of type ID so that getElementById works.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 27, 2005
    #2
    1. Advertising

  3. Billy

    Billy Guest

    Thanks Martin for a prompt reply,

    It works a treat, i've seen that syntax before now you've shown me it
    ... I will hopefully now remember it.

    Thanks very much for your time.

    Note: I am implementing the DOM object using .net c# and xpath is
    available.


    Regards

    Billy

    *** Sent via Developersdex http://www.developersdex.com ***
    Billy, Sep 27, 2005
    #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. Gilles T.
    Replies:
    8
    Views:
    2,073
    Alessandro Zifiglio
    Jan 5, 2004
  2. jm
    Replies:
    1
    Views:
    825
  3. Paul
    Replies:
    8
    Views:
    3,286
  4. Franck
    Replies:
    3
    Views:
    2,368
    Eliyahu Goldin
    Aug 25, 2005
  5. Ferret Face
    Replies:
    3
    Views:
    29,880
    Ferret Face
    Oct 4, 2005
Loading...

Share This Page