XmlTextReader Encoding

Last post 07-02-2008 3:28 PM by Ganeshyb. 3 replies.

Sort Posts:

  • XmlTextReader Encoding

    07-02-2008, 1:31 AM
    • Loading...
    • rbadis
    • Joined on 04-23-2007, 7:44 AM
    • Posts 222

     Hi,

     

    I' reading from an XML file to a database, but the problem that if a node contain a Comma Character "," I'm getting the following error message:   

    "Invalid character in the given encoding. Line 28, position 22.and System.Xml.XmlTextReader "

    So, is there a way to ignore and continue or read the comma as it is? 

     

    That's the top bit of my XML file:

    <?xml version="1.0" encoding="UTF-8" ?>
    <table name="BusinessRegisterList">
      <BusinessRegister>
        <RegisterNumber>E/00214</RegisterNumber>
        <ABN>62 000 164 803</ABN>
        <TradingName>Peakhurst Bowling &amp; Recreation Club Ltd - Bar</TradingName>
        <BusinessType>Registered Club</BusinessType>
        <FANumber>5592</FANumber>
        <RiskCategory>P2</RiskCategory>
        <BusinessContact_Address_Address1>7 Holley Road </BusinessContact_Address_Address1>
        <BusinessContact_Address_Suburb>BEVERLY HILLS</BusinessContact_Address_Suburb>
        <BusinessContact_Address_State>NSW</BusinessContact_Address_State>
        <BusinessContact_Address_PostCode>2222</BusinessContact_Address_PostCode>
        <BusinessContact_WorkPhoneNumber>02 9153 7756</BusinessContact_WorkPhoneNumber>
        <BusinessContact_MobileNumber>0402 643 853</BusinessContact_MobileNumber>
        <ContactName>Anthony Riley</ContactName>
        <ContactDetails_WorkPhoneNumber>02 9153 7756</ContactDetails_WorkPhoneNumber>
        <CompanyName>The Peakhurs, Bowling and Recreation Club Limited</CompanyName>
        <CompanyContact_Address_Address1>PO Box 44 </CompanyContact_Address_Address1>
        <CompanyContact_Address_Suburb>Peakhurst </CompanyContact_Address_Suburb>
        <CompanyContact_Address_PostCode>2210</CompanyContact_Address_PostCode>
        <CompanyContact_Faxnumber>5592</CompanyContact_Faxnumber>
      </BusinessRegister>
      <BusinessRegister>
        <RegisterNumber>E/00214</RegisterNumber>
        <ABN>80 711 521 885</ABN>
        <TradingName>Peakhurst Bowling &amp; Recreation Club Ltd -  The View Caf</TradingName>
        <BusinessType>Caf‚</BusinessType>
        <FANumber>43552</FANumber>
        <RiskCategory>P2</RiskCategory>
        <BusinessContact_Address_Address1>7 Holley Road </BusinessContact_Address_Address1>
        <BusinessContact_Address_Suburb>BEVERLY HILLS</BusinessContact_Address_Suburb>
        <BusinessContact_Address_State>NSW</BusinessContact_Address_State>
        <BusinessContact_Address_PostCode>2222</BusinessContact_Address_PostCode>
        <BusinessContact_WorkPhoneNumber>02 9153 7756</BusinessContact_WorkPhoneNumber>
        <BusinessContact_MobileNumber>0412 493 377</BusinessContact_MobileNumber>
        <ContactName>Veasna Bryan </ContactName>
        <ContactPosition>Proprietor</ContactPosition>
        <ProprietorName>Veasna Bryan</ProprietorName>
        <CompanyName>Mattina Caf Pty Ltd ATF Mattina Family Trust</CompanyName>
        <CompanyContact_Address_Address1>PO Box 44 </CompanyContact_Address_Address1>
        <CompanyContact_Address_Suburb>Peakhurst</CompanyContact_Address_Suburb>
        <CompanyContact_Address_PostCode>2210</CompanyContact_Address_PostCode>
        <CompanyContact_Faxnumber>43552</CompanyContact_Faxnumber>
      </BusinessRegister>
      <BusinessRegister>
    .
    .
    .

    </table>

     

     

     

    Thanks

    badis
  • Re: XmlTextReader Encoding

    07-02-2008, 2:21 AM
    Answer
    • Loading...
    • Ganeshyb
    • Joined on 11-02-2007, 12:07 AM
    • Posts 201

    Try using  StreamReader to load the xml with encoding

    ex:

     

     using (System.IO.StreamReader stReader = new System.IO.StreamReader(@"C:\Example\file1.xml", System.Text.Encoding.UTF8))
                {
                    System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stReader);
                    while (reader.Read())
                    {
                        Console.WriteLine("{0}:{1}", reader.Name, reader.Value);
                    }
                    reader.Close();
                }
     
    Thanks
    Ganesh


    If you find my reply help you Mark it Answered.
  • Re: XmlTextReader Encoding

    07-02-2008, 2:48 AM
    • Loading...
    • rbadis
    • Joined on 04-23-2007, 7:44 AM
    • Posts 222

     

    Thanks it did work, but the Comman Charachter has be written as "?" in my database! and I don't know why.

    Thanks anyway.

    badis
  • Re: XmlTextReader Encoding

    07-02-2008, 3:28 PM
    • Loading...
    • Ganeshyb
    • Joined on 11-02-2007, 12:07 AM
    • Posts 201

    How are you stroing the data in DB (data type)

    Thanks
    Ganesh


    If you find my reply help you Mark it Answered.
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter