3

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?

5
  • We need more details: is this XML local file on the server? Or is it located on different machine/website? Commented Dec 20, 2011 at 9:06
  • This XML is located on local server only Commented Dec 20, 2011 at 9:23
  • So Rory answer should be correct then.. Commented Dec 20, 2011 at 9:28
  • @Shadow: Not quite. Subramani are you interested in the attributes on both Page elements and Control elements? Commented Dec 20, 2011 at 13:21
  • Yes i need for both Page and Control Elements Commented Dec 22, 2011 at 12:40

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

5 Comments

Its not working... the XML file is available on same virtual directory. anythink needs to include? Note: I am using IE 8
@subramani just change oXML.LoadXML(sXML) to oXML.Load("filename.xml")
@Shadow: you need Server.MapPath as well.
@AnthonyWJones true, my bad! Rory can you please edit your post with this option as well?
<%@ Language=VBScript %><% Option Explicit %><HTML> <HEAD> </HEAD> <BODY> <% On Error Resume Next Dim oXML Set oXML = Server.CreateObject("Microsoft.XMLDOM") oXML.async = False oXML.load (Server.MapPath("/Test1/PortalConfiguration.xml")) Dim sName Dim sIsCaptured For Each oNode In oXML.SelectNodes("/PageMapping/Applications/Application/Page") sName = oNode.GetAttribute("name") sIsCaptured = oNode.GetAttribute("IsCaptured") response.write("SName" & sName) response.write("is" & sIsCaptured) Next Set oXML = Nothing %> </BODY> </HTML>.The aboce code is not working. Please correct me if i am wrong.
0

Change line 4 and 5 to these:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.