简体   繁体   中英

decoding xml in classic asp

I have the following xml that I need to place element names and values into a database

<questionnaireData>
  <data>
    <name>Dave</name>
    <jobRole>Developer</jobRole>
    <q1>my response</q1>
  </data>
  <data>
    <name>John</name>
    <jobRole>Sales</jobRole>
    <q10>another response</q1>
  </data>
</questionnaire>

The problem I have is decoding through the document with classic asp.

I have

For Each entry In xml.selectNodes("questionnaireData/data")

which correctly gives me the two nodes in the examples, but then for each of these 2 nodes I need to iterate through the contents to update my database. The node names at this level could be very varied.

Could anyone help me to loop through the contents of the "data" node and get at the node name and value for each of the children.

Many thanks

You can acquire the values need using code like this:

Dim name, value

For Each elem in entry.SelectNodes("*")
    name = elem.nodeName
    value = elem.text
    // Do stuff with name/value pair

Next

However there may be a better way to handle XML if you are only updating a database with the XML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM