Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parsing Attributes Values in XML into an array

Posted on 2004-04-12
4
Medium Priority
?
670 Views
Last Modified: 2013-11-19
This is probably my 5th question and so far i learned a lots thru this portal.

Q) I have a xml file that i need to parse the attribute values. The sample file is

<Request>
      <PunchOutSetupRequest operation="create">
                  <BuyerCookie>34234234ADFSDF234234</BuyerCookie>
                  <Extrinsic name="FirstName">Sam</Extrinsic>
                  <Extrinsic name="LastName">Trusky</Extrinsic>
                  <Extrinsic name="Email">abc@mail.com</Extrinsic>
      </PunchOutSetupRequest>
</Request>

I need to retrieve the firstname, lastnamem and Email from the xml file.

Dim objPerson
Set objPerson = Server.CreateObject("Msxml2.DOMDocument")
objPerson .async = false
Response.Write "Ready to execute XML.load()"
objPerson.load(Server.MapPath("PunchOutOrderMessage.xml"))
objPerson.documentElement.firstChild
objPerson.getAttribute("FIRSTNAME")
....

I want to first store the values in a array since the list of attributes can vary.

Any help is appreciated.

0
Comment
Question by:CIT_DEV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 10806243
There is no attribute named "FIRSTNAME" in your example.  Remember, everything is case sensitive, and you use the name of the attribute, not the value.  Perhaps you're trying to do this:

objPerson.childNodes.item(1).getAttribute("name").nodeValue

This returns "FirstName"

Or are you trying to get "Sam" as the returned value?  If so, you're looking for an <Extrinsic> node whose "name" attribute equals "FirstName".  SelectSingleNode and XPath is the easiest way to do this, but that doesn't work on all parsers.  What parser are you using?

Regards,
Mike Sharp
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10806339
I am looking to retrieve the vaues of Sam and store it in a variable array item - FirstName

I am using Xpath.
0
 
LVL 1

Author Comment

by:CIT_DEV
ID: 10806702
This is the exact progam i am using..

Set objXML=Server.CreateObject("Microsoft.XMLDOM")
Dim aOrder(3,5)
If Request.QueryString("id") = 1 then
      objXML.load(Server.MapPath("Attributes.xml"))
End If

Response.Write "<textarea rows=20 cols=100  id=textarea1 name=textarea1>" & objXML.xml  & "</textarea>"
             
If objXML.parseError.errorCode <> 0 then
      Response.write "Error loading the resource file "
Else
    Path            =      "/Request/PunchOutSetupRequest/Extrinsic" & "/text()"
    Set nodes      =      objXML.selectNodes(path)
    For each x in nodes
      Response.write  x.xml
   Next
                  
End If
      
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 750 total points
ID: 10807130
Don't use Microsoft.XMLDOM.  That's the old parser.  Use Msxml2.DOMDocument as in your first post.

This:

    Path          =     "/Request/PunchOutSetupRequest/Extrinsic" & "/text()"

selects the all of the Extrinsic text node children...probably not what you want.  Try this:

    Path          =     "/Request/PunchOutSetupRequest/Extrinsic[@name = 'FirstName']"
    Set nodes     =     objXML.selectNodes(path)
    For each x in nodes
      Response.write  x.text
    Next
 
This selects all Extrinsic nodes whose name attribute equals "FirstName".

Regards,
Mike Sharp
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question