locked
hexadecimal value 0x20, cannot be included !!! RRS feed

  • Question

  • Hi

    Am writing some data in XML file by retrieving from the same class..


      using (XmlWriter writer = XmlWriter.Create("C:\\Users\\Jaishree\\Desktop\\AllAccounts.xml", null))
                {
                    writer.WriteStartDocument();

                    writer.WriteStartElement("Accounts");

                 
                    foreach (BankAccount cust in allAccounts)
                    {
                       // writer.WriteStartElement("Accounts");

                      
                        writer.WriteElementString("CustomerName", cust.Customer.CustomerName);
                        writer.WriteElementString("Account Number", cust.AccountNumber.ToString());
                        writer.WriteElementString("CustomerAddress", cust.Customer.CustomerAddress);
                        writer.WriteElementString("Balance", cust.Balance.ToString());
                        writer.WriteElementString("CustomerType", cust.TypeAccount.ToString());


                        //writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();

    But am getting an exception saying:

    "Invalid name character in 'Account Number'. The ' ' character, hexadecimal value 0x20, cannot be included in a name ," but i declared AccountNumber as integer...

    Any help...


    Sunday, January 20, 2013 11:20 AM

Answers

  • Hi,

    This is the hexadecimal code for the white space you have in "Account Number". Just use "AccountNumber" instead as you have done for CustomerType...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Proposed as answer by TSoftware-Old Sunday, January 20, 2013 12:52 PM
    • Marked as answer by Jayashree.R.D Sunday, January 20, 2013 1:10 PM
    Sunday, January 20, 2013 12:18 PM
  • Hi, 

    It will work, if you remove the space in "Account Number" element. Please refer below

    writer.WriteElementString("AccountNumber", cust.AccountNumber.ToString());


    Sunday, January 20, 2013 12:28 PM
  • I dont understand.Can you please explain!!!?

    XML Naming Rules

    XML elements must follow these naming rules:
    •Names can contain letters, numbers, and other characters
    •Names cannot start with a number or punctuation character
    •Names cannot start with the letters xml (or XML, or Xml, etc)
    •Names cannot contain spaces

    Any name can be used, no words are reserved.

    Reference: http://www.w3schools.com/xml/xml_elements.asp


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Marked as answer by Jayashree.R.D Sunday, January 20, 2013 1:09 PM
    Sunday, January 20, 2013 12:51 PM

All replies

  • Hi, the problem is the name of the element, not the value of it. Try to use Account%20Number or just AccountNumber.

    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Sunday, January 20, 2013 12:10 PM
  • I dont understand.Can you please explain!!!?
    Sunday, January 20, 2013 12:17 PM
  • Hi,

    This is the hexadecimal code for the white space you have in "Account Number". Just use "AccountNumber" instead as you have done for CustomerType...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    • Proposed as answer by TSoftware-Old Sunday, January 20, 2013 12:52 PM
    • Marked as answer by Jayashree.R.D Sunday, January 20, 2013 1:10 PM
    Sunday, January 20, 2013 12:18 PM
  • Hi, 

    It will work, if you remove the space in "Account Number" element. Please refer below

    writer.WriteElementString("AccountNumber", cust.AccountNumber.ToString());


    Sunday, January 20, 2013 12:28 PM
  • I dont understand.Can you please explain!!!?

    XML Naming Rules

    XML elements must follow these naming rules:
    •Names can contain letters, numbers, and other characters
    •Names cannot start with a number or punctuation character
    •Names cannot start with the letters xml (or XML, or Xml, etc)
    •Names cannot contain spaces

    Any name can be used, no words are reserved.

    Reference: http://www.w3schools.com/xml/xml_elements.asp


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Marked as answer by Jayashree.R.D Sunday, January 20, 2013 1:09 PM
    Sunday, January 20, 2013 12:51 PM