Results 1 to 2 of 2

Thread: reading xml file with asp.net

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830

    reading xml file with asp.net

    If I had the xml file below, could I read this and get
    the product id, code, description, weight, and price in an array where array(0, 3) would be row 1 weight data
    and array(1, 3) would be row 2 weight data?

    Trying to figure out xml and wondering if this is even possible.
    What's the easiest way to get data from an xml file to load only the data you need to say a file or database?

    Thanks for the help in advance.


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE SiteExport SYSTEM "http://........./TestSiteExport.dtd">
    <SiteExport>
      <Settings>
        <Published timestamp="1084036444"/>
        <Locale code="C" name="English" encoding="iso-8859-1"/>
        <SiteName>Test Site</SiteName>
        <Currency>USD</Currency>
        <ShipMethods>
          <ShipMethod>UPS Ground Residential</ShipMethod>
          <ShipMethod>3 Day Select Residential</ShipMethod>
        </ShipMethods>
        <PayMethods>
          <PayMethod>Cashier's Check or Money Order</PayMethod>
          <PayMethod>Discover</PayMethod>
          <PayMethod>MasterCard</PayMethod>
          <PayMethod>Visa</PayMethod>
        </PayMethods>
      </Settings>
      <Products>
        <Product Id="123">
          <Code>123 - Bags</Code>
          <Description>123 Description</Description>
          <Url>http://www.site.com/test1.htm</Url>
          <Weight>1</Weight>
          <Orderable>YES</Orderable>
          <Taxable>YES</Taxable>
          <Pricing>
            <BasePrice>19.95</BasePrice>
            <LocalizedBasePrice>19.95</LocalizedBasePrice>
            <AdditionalCharge>0</AdditionalCharge>
          </Pricing>
          <Caption>123 Bags - Package of 10</Caption>
        </Product>
        <Product Id="234">
          <Code>Zebra 234</Code>
          <Description>Zebra 234</Description>
          <Url>http://www.site.com/test2.html</Url>
          <Weight>22</Weight>
          <Orderable>YES</Orderable>
          <Taxable>YES</Taxable>
          <Pricing>
            <BasePrice>25.75</BasePrice>
            <LocalizedBasePrice>25.75</LocalizedBasePrice>
            <AdditionalCharge>0</AdditionalCharge>
          </Pricing>
          <Caption>Zebra 234</Caption>
        </Product>
         </Products>
    </SiteExport>

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Minnesota
    Posts
    830
    Well, still struggling with this. I can pull the Pricing information out but for some reason I can't do the same for the Product Id section.

    I will post the code that I have working with the xml data above that does work but I need some help with the best way to get the Product Id info (code, url, weight, plus the pricing)

    Thanks.

    Code:
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Xml" %>
    
    <Script Runat="server">
    Sub Page_Load
    	Dim sValue1 as String
    	Dim sValue2 as String
    	Dim dstList as DataSet
    	Dim objDataDocument as XmlDataDocument
    	Dim objLists as XmlNodeList
    	Dim objList as XmlNode
    	Dim iLoop as Integer
    	
    	dstList = New DataSet()
    	dstList.ReadXml(MapPath("testdata.xml"))
    	
    	objDataDocument = New XmlDataDocument(dstList)
    	objLists = objDataDocument.GetElementsByTagName("Pricing")
    	'First line displays count
    	lblTable1.Text &= objLists.Count()
    	
    	'Loop through list
    	For iLoop = 0 To objLists.Count() - 1
    		objList = objLists.ItemOf(iLoop)
    		sValue1 = objList("BasePrice").InnerText
    		sValue2 = objList("LocalizedBasePrice").InnerText
    		lblTable1.Text &= "<br>" & sValue1 & "-" & sValue2
    	Next
    	
    End Sub
    </Script>
    <html>
    <head>
    <title>Read XML</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <asp:label ID="lblTable1" Font-Size="12pt" runat="server" />
    </body>
    </html>

Posting Permissions

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



Click Here to Expand Forum to Full Width