使用Classic ASP获取节点属性的值

时间:2011-12-20 07:36:35

标签: xml asp-classic

我有以下XML架构:

<?xml version="1.0" encoding="utf-8"?>
  <PageMapping>
    <Applications>
       <Application name="xxx">
         <Page name='Default.aspx' IsCaptured = "true" >
            <Control name="btnSearch" IsCaptured = "true"/>
            <Control name="btnSave" IsCaptured = "true"/>
            <Control name="btnClick" IsCaptured = "true"/>
         </Page>
         <Page name='Login.aspx' IsCaptured = "true">
            <Control name="btnSearch" IsCaptured = "true"/>
         </Page>
         <Page name='Home.aspx' IsCaptured = "true" >
            <Control name="btnSearch" IsCaptured = "true"/>
         </Page>
         <Page name='User.aspx' IsCaptured = "true" />
     </Application>
   </Applications>
 </PageMapping>

使用ASP,我如何获得“name”和“IsCaptured”的值?我尝试过各种不同的方法,但似乎没什么用。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

试试这个:

Set oXML = Server.CreateObject("MSXML2.DomDocument.4.0")
oXML.LoadXML(sXML) ' sXML is a variable containing the content of your XML file

For Each oNode In oXML.SelectNodes("/PageMapping/Applications/Application/Page")
    sName = oNode.GetAttribute("Name")
    sIsCaptured = oNode.GetAttribute("IsCaptured")

    ' Do something with these values here
Next

Set oXML = Nothing

答案 1 :(得分:0)

将第4行和第5行更改为:

Dim sName : sName =  oNode.GetAttribute("Name")
Dim sIsCaptured : sIsCaptured =  oNode.GetAttribute("IsCaptured")