Does not recognise XML Format

Last post 05-08-2008 10:33 PM by Samu Zhang - MSFT. 4 replies.

Sort Posts:

  • Does not recognise XML Format

    05-07-2008, 6:04 AM
    • Loading...
    • sunhuman
    • Joined on 03-23-2008, 11:22 AM
    • Posts 22

    Below is an XML that was generated from a Dataset

    <?xml version="1.0" standalone="yes"?>
     <PC>
        <ID>8</ID>
        <location>Qatar</location>
        <assembled>No</assembled>
        <brand>IBM THINKPAD T43</brand>
        <processor>Centrino 1.8 Ghz</processor>
        <memory>512 MB</memory>
        <hdd>80 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>4/28/2005</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>User 7</username>
        <entry_no>1</entry_no>
      </PC>
      <PC>
        <ID>199</ID>
        <location>Fujairah</location>
        <assembled>Yes</assembled>
        <brand>HP 6720S</brand>
        <processor>2 Ghz</processor>
        <memory>1 GB</memory>
        <hdd>120 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>2008</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>Ajay Lawrence</username>
        <entry_date>4/15/2008</entry_date>
      </PC>
      <PC>
        <ID>78</ID>
        <location>Dubai</location>
        <assembled>Yes</assembled>
        <brand>Unitron-Abdulla</brand>
        <processor>P4 2.4Ghz</processor>
        <memory>256 MB</memory>
        <hdd>40 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>11/1/2002</purchase_date>
        <machine_type>DESKTOP</machine_type>
        <username>Abdulla</username>
      </PC>

    I have used this an XML Datasource Control.

    When adding the source to an  DropDownList Control it does not identify the fields

    But instead if I use the below the XML File I got from a tutorial , it works fine

    What could be wrong? Please help

    <?xml version="1.0" encoding="utf-8" ?>
    <People>
        <Person FirstName="Jake" LastName="Stone">
          <Address>
            <Street>345 Maple St.</Street>
            <City>Redmond</City>
            <Region>WA</Region>
            <ZipCode>01434</ZipCode>
          </Address>
          <Job>
            <Title>CEO</Title>
            <Description>Develops company strategies.</Description>
          </Job>
        </Person>
        <Person FirstName="Jacob" LastName="Ladder">
          <Address>
            <Street>123 Elm St.</Street>
            <City>Seattle</City>
            <Region>WA</Region>
            <ZipCode>11223</ZipCode>
          </Address>
          <Job>
            <Title>Attorney</Title>
            <Description>Reviews legal issues.</Description>
          </Job>
        </Person>
        <Person FirstName="Angela" LastName="Hound">
          <Address>
            <Street>34 Palm Avenue</Street>
            <City>Renton</City>
            <Region>WA</Region>
            <ZipCode>63910</ZipCode>
          </Address>
          <Job>
            <Title>IT Director</Title>
            <Description>In charge of corporate network.</Description>
          </Job>
        </Person>
    </People>

  • Re: Does not recognise XML Format

    05-07-2008, 7:02 AM
    • Loading...
    • claytonc
    • Joined on 04-23-2008, 1:43 PM
    • Posts 29

    Hi,

    If you try to open that XML file in IE, you'll see that it will give you an error! That's because you don't have a root element;

    <?xml version="1.0" standalone="yes"?>
    <root>
     <PC>
        <ID>8</ID>
        <location>Qatar</location>
        <assembled>No</assembled>
        <brand>IBM THINKPAD T43</brand>
        <processor>Centrino 1.8 Ghz</processor>
        <memory>512 MB</memory>
        <hdd>80 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>4/28/2005</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>User 7</username>
        <entry_no>1</entry_no>
      </PC>
      <PC>
        <ID>199</ID>
        <location>Fujairah</location>
        <assembled>Yes</assembled>
        <brand>HP 6720S</brand>
        <processor>2 Ghz</processor>
        <memory>1 GB</memory>
        <hdd>120 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>2008</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>Ajay Lawrence</username>
        <entry_date>4/15/2008</entry_date>
      </PC>
      <PC>
        <ID>78</ID>
        <location>Dubai</location>
        <assembled>Yes</assembled>
        <brand>Unitron-Abdulla</brand>
        <processor>P4 2.4Ghz</processor>
        <memory>256 MB</memory>
        <hdd>40 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>11/1/2002</purchase_date>
        <machine_type>DESKTOP</machine_type>
        <username>Abdulla</username>
      </PC>
    </root>

    this should work fine...
     

    Clayton
    If this post answered your question please 'Mark as Answer'
  • Re: Does not recognise XML Format

    05-07-2008, 7:26 AM
    • Loading...
    • sunhuman
    • Joined on 03-23-2008, 11:22 AM
    • Posts 22

     

    Sorry, this did not work. The dropdownlist that I created is still unable to locate the field names from the XML document.

  • Re: Does not recognise XML Format

    05-07-2008, 9:19 AM
    • Loading...
    • claytonc
    • Joined on 04-23-2008, 1:43 PM
    • Posts 29

    Can you please paste the code? 

    Clayton
    If this post answered your question please 'Mark as Answer'
  • Re: Does not recognise XML Format

    05-08-2008, 10:33 PM
    Answer

    Hi sunhuman ,

    First , add one root Element to your xml file.

    And you can bind dropdownlist to one DataSet object instead of using XmlDataSource.

     

    <PCS>
      <PC>
        <ID>8</ID>
        <location>Qatar</location>
        <assembled>No</assembled>
        <brand>IBM THINKPAD T43</brand>
        <processor>Centrino 1.8 Ghz</processor>
        <memory>512 MB</memory>
        <hdd>80 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>4/28/2005</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>User 7</username>
        <entry_no>1</entry_no>
      </PC>
      <PC>
        <ID>199</ID>
        <location>Fujairah</location>
        <assembled>Yes</assembled>
        <brand>HP 6720S</brand>
        <processor>2 Ghz</processor>
        <memory>1 GB</memory>
        <hdd>120 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>2008</purchase_date>
        <machine_type>Laptop</machine_type>
        <username>Ajay Lawrence</username>
        <entry_date>4/15/2008</entry_date>
      </PC>
      <PC>
        <ID>78</ID>
        <location>Dubai</location>
        <assembled>Yes</assembled>
        <brand>Unitron-Abdulla</brand>
        <processor>P4 2.4Ghz</processor>
        <memory>256 MB</memory>
        <hdd>40 GB</hdd>
        <os>Windows XP Professional</os>
        <purchase_date>11/1/2002</purchase_date>
        <machine_type>DESKTOP</machine_type>
        <username>Abdulla</username>
      </PC>
    </PCS>
      
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("XMLFile33.xml"));
            this.DropDownList1.DataSource = ds;
            DropDownList1.DataTextField = "location";
            DropDownList1.DataValueField = "ID";
            DropDownList1.DataBind();

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (5 items)