How would I parse and process this XML

Results 1 to 2 of 2

Thread: How would I parse and process this XML

  1. #1
    Join Date
    Dec 1969

    Default How would I parse and process this XML

    I have a request that will contain some xml. The only thing about this xml that will vary is the number of groups that the xml will contain. Otherwise, here is what it will look like:<BR><BR>&#060;addUser&#062;<BR>&#060;user firstname="joe" lastname="blo" email="" username="jo" password="blo" /&#062;<BR>&#060;groups&#062;<BR>&#060;group value="1" /&#062;<BR>&#060;group value="2" /&#062;<BR>&#060;/groups&#062;<BR>&#060;/addUser&#062;<BR><BR>My questions are:<BR>(1)How would I parse this xml in ASP and extract the values for the attributes of the user node?<BR><BR>(2) How would I iterate over the groups to extract all of the group elements, regardless of how many there may be(it will be variable for each user?<BR><BR>Thanks for any help you can give!

  2. #2
    Join Date
    Dec 1969

    Default Couple of ways....

    option explicit<BR><BR>dim objXML<BR>dim attTemp<BR>dim i<BR><BR>Response.Write("&lt;b&gt;Down and Dirty.....&lt;/b&gt;&lt;br&gt;")<BR>set objXML = server.CreateObject("MSXML2.DOMDocument")<BR>objXM L.async = "false"<BR>objXML.load(server.MapPath("user.xml")) <BR><BR>set attTemp = objXML.selectSingleNode("//user/@firstname")<BR>Response.Write("FirstName: " & attTemp.text & "&lt;br&gt;")<BR><BR>set attTemp = objXML.selectSingleNode("//user/@lastname")<BR>Response.Write("LastName: " & attTemp.text & "&lt;br&gt;")<BR><BR>set attTemp = objXML.selectSingleNode("//user/@email")<BR>Response.Write("Email: " & attTemp.text & "&lt;br&gt;")<BR><BR>set attTemp = objXML.selectSingleNode("//user/@username")<BR>Response.Write("UserName: " & attTemp.text & "&lt;br&gt;")<BR><BR>set attTemp = objXML.selectSingleNode("//user/@password")<BR>Response.Write("Password: " & attTemp.text & "&lt;br&gt;&lt;br&gt;&lt;br&gt;")<BR><BR>Response. Write("&lt;b&gt;Nice and Easy.....&lt;/b&gt;&lt;br&gt;")<BR>set attTemp = objXML.selectSingleNode("//user").attributes <BR>for i = 0 to attTemp.length - 1<BR> Response.Write(attTemp(i).name & ": " & attTemp(i).text & "&lt;br&gt;")<BR>next<BR><BR>set attTemp = nothing<BR>set objXML = nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts