By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,867 Members | 1,981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,867 IT Pros & Developers. It's quick & easy.

Retrieve informations from XML in ASP?

P: 80
Hi all.

I need to extract ALL information from an XML document in classic ASP. I have tried alot, but cant seem to find the best way to do this. Below theres an example of the XML document and its associated XSD document. My provider runs IIS 6.0 and using
Expand|Select|Wrap|Line Numbers
  1. CreateObject("MSXML.DOMDocument")
have worked with my initial testings.

The XML:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="oemPriceXMLList.xsd">
  3.  
  4. <group name="">
  5. </group>
  6. <group name="Software">
  7. <product id="50634">
  8. <name>Adobe Premiere Elements UK V8</name>
  9. <stock>Yes</stock>
  10. <weight>0.5</weight>
  11. <model>65045809</model>
  12. <shortDescription>Adobe Premiere Elements - ( v. 8 )</shortDescription>
  13. <manufacturerName>Adobe</manufacturerName>
  14. <manufacturerURL>http://www.adobe.com/</manufacturerURL>
  15. <price>475</price>
  16. </product><product id="50635">
  17. <name>Adobe Photoshop</name>
  18. <stock>Yes</stock>
  19. <weight>0.5</weight>
  20. <model>65045041</model>
  21. <shortDescription>Adobe Photoshop</shortDescription>
  22. <manufacturerName>Adobe</manufacturerName>
  23. <manufacturerURL>http://www.adobe.com/</manufacturerURL>
  24. <price>479</price>
  25. </product></group>
The XSD:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2.  
  3. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  4.  
  5.  
  6.  
  7. <!-- definition of simple elements -->
  8.  
  9. <xs:element name="name" type="xs:string"/>
  10.  
  11. <xs:element name="price" type="xs:positiveInteger"/>
  12.  
  13. <xs:element name="stock" type="xs:string"/>
  14.  
  15. <xs:element name="weight" type="xs:decimal"/>
  16.  
  17. <xs:element name="model" type="xs:string"/>
  18.  
  19. <xs:element name="shortDescription" type="xs:string"/>
  20.  
  21. <xs:element name="manufacturerName" type="xs:string"/>
  22.  
  23. <xs:element name="manufacturerURL" type="xs:string"/>  
  24.  
  25.  
  26.  
  27. <!-- definition of attributes -->
  28.  
  29. <xs:attribute name="name" type="xs:string"/>
  30.  
  31. <xs:attribute name="id" type="xs:positiveInteger"/>    
  32.  
  33.  
  34.  
  35. <!-- definition of complex elements -->
  36.  
  37. <xs:element name="product">
  38.  
  39.   <xs:complexType>  
  40.  
  41.     <xs:sequence>
  42.  
  43.       <xs:element ref="name"/>
  44.  
  45.          <xs:element ref="price"/>
  46.  
  47.          <xs:element ref="stock"/>
  48.  
  49.          <xs:element ref="weight"/>
  50.  
  51.          <xs:element ref="model"/>
  52.  
  53.          <xs:element ref="shortDescription"/>
  54.  
  55.          <xs:element ref="manufacturerName"/>
  56.  
  57.          <xs:element ref="manufacturerURL"/>                          
  58.  
  59.     </xs:sequence>
  60.  
  61.   </xs:complexType>
  62.  
  63. </xs:element>
  64.  
  65.  
  66.  
  67. <xs:element name="group">
  68.  
  69.   <xs:complexType>
  70.  
  71.     <xs:sequence>
  72.  
  73.         <xs:element ref="product"/>
  74.  
  75.     </xs:sequence>
  76.  
  77.     <xs:attribute ref="id" use="required"/>    
  78.  
  79.   </xs:complexType>  
  80.  
  81. </xs:element>
  82.  
  83.  
  84.  
  85. <xs:element name="products">
  86.  
  87.   <xs:complexType> 
  88.  
  89.     <xs:sequence>
  90.  
  91.       <xs:element ref="group"/>
  92.  
  93.     </xs:sequence>
  94.  
  95.   </xs:complexType>    
  96.  
  97. </xs:element>  
  98.  
  99.  
  100.  
  101. </xs:schema>
I beleieve the best way to get through this would be looping through each <product name="xxx"> AND THEN loop through each <product id="xxx"> and show its elements..

Dont know if this is correct? As I wrote I have tried ALOT and there for would be very glad if someone could guide me all the way through this one :D

Thanks!
Nov 16 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.