简体   繁体   English

在经典ASP中解码xml

[英]decoding xml in classic asp

I have the following xml that I need to place element names and values into a database 我有以下xml,需要将元素名称和值放入数据库中

<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. 我遇到的问题是使用经典的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. 但是,如果仅使用XML更新数据库,则可能会有更好的方式处理XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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