2011-12-20 46 views
2

的价值,我有以下XML架构:使用经典的ASP获取一个节点属性

<?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,我怎么会得到“名”和“IsCaptured”的价值?我尝试了各种不同的方法,但似乎没有任何工作。有任何想法吗?

+0

我们需要更多的细节:这是本地XML文件的服务器上?或者它位于不同的机器/网站上? – 2011-12-20 09:06:47

+0

此XML仅位于本地服务器 – subramani 2011-12-20 09:23:39

+0

因此[Rory答案](http://stackoverflow.com/a/8573002/447356)应该是正确的然后.. – 2011-12-20 09:28:32

回答

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 
+0

它不工作...该XML文件可在相同的虚拟目录。 anythink需要包括?注意:我正在使用IE 8 – subramani 2011-12-20 09:41:10

+0

@subramani只需将'oXML.LoadXML(sXML)'更改为'oXML.Load(“filename.xml”)' – 2011-12-20 13:26:37

+1

@Shadow:同样需要Server.MapPath。 – AnthonyWJones 2011-12-20 13:29:22

0

更改行4和5,这些:

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