Read/Search XML in ASP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pheddy
    New Member
    • Dec 2008
    • 80

    Read/Search XML in ASP?

    Hi All.

    I am having trouble getting the right code to work with XML.. I have this file:

    Code:
      <?xml version="1.0" encoding="ISO-8859-1" ?> 
    - <products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PriceList.xsd">
      <group name="" /> 
    - <group name="Software">
    - <product id="5063441">
      <name>Some Soft</name> 
      <stock>Yes</stock> 
      <weight>0.5</weight> 
      <model>65045809</model> 
      <shortDescription>SomeSoft...</shortDescription> 
      <manufacturerName>Adobe</manufacturerName> 
      <manufacturerURL>http://www.adobe.com/</manufacturerURL> 
      <price>4754545</price> 
      </product>
    This file contains 10.000 Products like the one above, and I need to search it trough and extract its elements.

    I have tried looking around the web for solutions but it seems that this (I would imagine - easy task) arent that simple..
  • Pheddy
    New Member
    • Dec 2008
    • 80

    #2
    Maybe someone could help me to a working and updated guide somewhere?

    Thanks again.

    Comment

    • azrar
      New Member
      • Nov 2008
      • 11

      #3
      I recommend reading up on XPath so you know how to target the data you want in an XML file.

      Sorry! We can't seem to find the resource you're looking for


      Here's an example of how to implement xpath in ASP:
      Code:
      <%
      set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
      xmlDoc.async = False
      xmlDoc.LoadXML xml_data
      
      set nodes = xmlDoc.selectNodes("/products/product[@id='5063441']") '- this is xpath
      
      For Each n in nodes
       '-- do stuff here
      Next
      
      set nodes=nothing
      set xmlDoc = nothing
      %>

      Comment

      Working...