Read XML string attributes with Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rjvrnjn
    New Member
    • Apr 2007
    • 26

    Read XML string attributes with Javascript

    I have a XML string returned from SQL server as a result of select query. The XML string looks like:

    [CODE=xml]<row col1="value1", col2="value2"/><row col1="value12", col2="value22"/>[/CODE]

    At the client side I want to read a specific row based on the user selected value.

    For example, if the user selects a drop down item whose value is "value1" I want to read the col2 value from the xml string where the col1 value is "value1". How can I achieve this? It seems doable, but being a n00b in web programming I'm unable to get hold of this thing.

    Thanks.
    Last edited by gits; Apr 28 '08, 09:32 AM. Reason: added code tags
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    This link may help u

    http://www.codeproject .com/KB/scripting/xmljs.aspx



    Originally posted by rjvrnjn
    I have a XML string returned from SQL server as a result of select query. The XML string looks like:

    <row col1="value1", col2="value2"/><row col1="value12", col2="value22"/>

    At the client side I want to read a specific row based on the user selected value.

    For example, if the user selects a drop down item whose value is "value1" I want to read the col2 value from the xml string where the col1 value is "value1". How can I achieve this? It seems doable, but being a n00b in web programming I'm unable to get hold of this thing.

    Thanks.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by vee10
      This link may help u

      http://www.codeproject .com/KB/scripting/xmljs.aspx
      Ugh! IE-only :(

      Try something cross-browser instead. See how you can access nodes.

      Comment

      • rjvrnjn
        New Member
        • Apr 2007
        • 26

        #4
        Hmmm... I'd been through those articles. On looking through the code more I realised that my XML was not well formed. The root element was missing (as the XML code emited by SQL server didn't have the root node). I modified the XML string to enclose it between <root></root> (it could have been anything else). And wow that worked.

        Thanks guys for your time.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Seeing as you said you were new to all this, I thought a good tutorial would help, not to mention the fact that I hate IE-only tutorials when there's a clear alternative for other browsers.

          Anyway, glad that you've fixed it. That is one of the first things to check.

          Comment

          Working...