Using Classic ASP to get value of a node attribute

本秂侑毒 提交于 2019-12-11 02:14:24

问题


I have the following XML schema:

<?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>

Using ASP, how would I get the value of "name" and "IsCaptured"? I have tried all sorts of different methods, but nothing seems to work. Any ideas?


回答1:


Try this:

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



回答2:


Change line 4 and 5 to these:

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


来源:https://stackoverflow.com/questions/8572132/using-classic-asp-to-get-value-of-a-node-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!