问题
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