Menu

Select children based on attributes?

2005-12-12
2013-05-20
  • twoeyedhuman

    twoeyedhuman - 2005-12-12

    I'm writing a simple program that selects user data based on attributes so I can learn more about programming.

    My problem is selecting children based on attributes.  Take this example:

    <?xml version="1.0" standalone=no>
    <user attribute="1234">
        <data>ect.</data>
    </user>

    <user attribute="5678">
        <data>example data</data>
    </user>

    I want to be able to select a <user> based on what the attribute equals.  Anyone know how to do this?

     
    • twoeyedhuman

      twoeyedhuman - 2005-12-12

      EDIT LAST MESSAGE:

      After looking for the forums again for an answer, I realized that there can only be one root node.

      The example should look like this:
      <!xml version="1.0" standalone=no>
      <root>

      <user attribute="1234">
      <data>ect.</data>
      </user>

      <user attribute="5678">
      <data>example data</data>
      </user>

      </root>

       
    • flamingheart

      flamingheart - 2005-12-12

      I think you can traverse all the nodes and check if the attribute of it equals to the attribute you designate.

       
      • twoeyedhuman

        twoeyedhuman - 2005-12-12

        Ahhh... Good idea - I'll do that, thank you.

         

Log in to post a comment.