Classic ASP XML - Listing both Elements and Attributes

belai123

New Member
Need your help figuring out the correct approach to listing XML elements, especially the ones that have attributes within them.NOTE: Parameter has the ID, Name and Topic attributes.NOTE: ParameterDetails has the Units, MinValue, MaxValue and Default attributes.NOTE: ParameterDescription and ParameterNotes do NOT have attributes.\[code\]<Parameter ID="12345" Name="Sales Type" Topic="Reference"> <ParameterDescription>Identifies type of sales</ParameterDescription> <ParameterNotes>Must be specified</ParameterNotes> <ParameterDetails Units="None" MinValue="http://stackoverflow.com/questions/12187925/0" MaxValue="http://stackoverflow.com/questions/12187925/10" Default="1" /> </Parameter>\[/code\]I am able to get all of the elements OR all of the attributes, but not both.Not familiar with Loops inside Loops...\[code\]Dim objxmlSet objxml = Server.CreateObject("Microsoft.XMLDOM")objxml.async = Falseobjxml.load (Server.MapPath("myFile.xml"))\[/code\]Here's the code for getting Elements...\[code\]set ElemParameter = objxml.getElementsByTagName("Parameter")set ElemDesc = objxml.documentElement.getAttribute("ParameterDescription")set ElemNotes = objxml.documentElement.getAttribute("ParameterNotes")For i=0 To (ElemParameter.length -1) Response.Write "Parameter Desc = " Response.Write(ElemDesc.item(i).Text) & "<br>" Response.Write "Parameter Notes = " Response.Write(ElemNotes.item(i).Text) & "<br><BR>"next\[/code\]Here's the code for getting Attributes...\[code\]For Each oNode In objxml.SelectNodes("/ProgrammingGuide/Parameters/Parameter") sID = oNode.GetAttribute("ID") sName = oNode.GetAttribute("Name") sTopic = oNode.GetAttribute("Topic") Response.Write "Parameter ID = "& sID &"<BR>" Response.Write "Parameter Name = "& sName &"<BR>" Response.Write "Parameter Topic = "& sTopic &"<BR><BR>"NextFor Each oNode In objxml.SelectNodes("/ProgrammingGuide/Parameters/ParameterDetails") sUnits = oNode.GetAttribute("Units") sMinVal = oNode.GetAttribute("MinValue") sMaxVal = oNode.GetAttribute("MaxValue") sDefault = oNode.GetAttribute("Default") Response.Write "Units = "& sUnits &"<BR>" Response.Write "Min Value = "http://stackoverflow.com/questions/12187925/& sMinVal &"<BR>" Response.Write "Max Value = "http://stackoverflow.com/questions/12187925/& sMaxVal &"<BR>" Response.Write "Default = "& sDefault &"<BR>"Next\[/code\]My desired results would look like this...\[code\]Parameter ID = 123456Parameter Name = Sales TypeParameter Topic = ReferenceParameter Desc = Identifies type of salesParameter Notes = Must be specifiedUnits = NoneMin Value = http://stackoverflow.com/questions/12187925/0Max Value = 10Default = 1\[/code\]As always, thanks for your help!
 
Back
Top