Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by uanmanarmy · Jul 09, 2014 at 11:46 AM · c#xmlparsexmlserializer

Invalid Encoding Specification Xml

Hi, I want to parse and Xml File. This is my code.

 string path = "Assets/Resources/Xml/Level1.xml";
     FileStream fsCPAP = null;
     XmlDocument xmlDoc = new XmlDocument ();
 
     void Start ()
     {
     
 
         if(File.Exists(path))
         {
             fsCPAP = new FileStream(path, FileMode.Open, FileAccess.Read);
             XmlTextReader rdrXml = new XmlTextReader(fsCPAP);
         do
         {
             switch(rdrXml.NodeType)
                 {
                 case XmlNodeType.Text:
                     print( rdrXml.Value);
                     break;
                 }
         }
 
         while(rdrXml.Read());        //as longs as read return true
         //Once Read() returns false, STOP!@!
         }
 
         else return;
 
 
     }



Xml file

 <?xml version = "1.0" encoding = "utf - 8"?>
 
 <levels>
         <level>
                 <Title>level1</Title>
                 <ItemNumber> 2 </ItemNumber>
         </level>
 
         <level>
                 <Title>level2</Title>
                 <ItemNumber> 2 </ItemNumber>
         </level>
 </levels>



The error I got at line XmlTextReader rdrXml = new XmlTextReader(fsCPAP);

XmlException: invalid encoding specification.

Any help ?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Graham-Dunnett · Jul 09, 2014 at 12:12 PM

Read exception, learn that something doesn't like the encoding. Look at XML, and notice that encoding has spaces in the format. Guess that the format needs to have the spaces removed.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Landern · Jul 09, 2014 at 12:30 PM 0
Share

Graham is spot on, further from the xml spec 4.3.3:

In an encoding declaration, the values " UTF-8 ", " UTF-16 ", " ISO-10646-UCS-2 ", and " ISO-10646-UCS-4 " should be used for the various encodings and transformations of Unicode / ISO/IEC 10646, the values " ISO-8859-1 ", " ISO-8859-2 ", ... " ISO-8859- n " (where n is the part number) should be used for the parts of ISO 8859, and the values " ISO-2022-JP ", " Shift_JIS ", and " EUC-JP " should be used for the various encoded forms of JIS X-0208-1997. It is recommended that character encodings registered (as charsets) with the Internet Assigned Numbers Authority [IANA-CHARSETS], other than those just listed, be referred to using their registered names; other encodings should use names starting with an "x-" prefix. X$$anonymous$$L processors should match character encoding names in a case-insensitive way and should either interpret an IANA-registered name as the encoding registered at IANA for that name or treat it as unknown (processors are, of course, not required to support all IANA-registered encodings).

further more, from IANA spec, you will find in the table exactly what Graham was referring to, it's case insenstive but the extra spaces change everything.

IANA Encoding/Character set lookup: Characters Sets

avatar image uanmanarmy · Jul 09, 2014 at 12:38 PM 0
Share

Yeah!, that was the problem, haha, im so dumb :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How do I make this XML file parser work in Unity 1 Answer

XML parsing c# in unity 1 Answer

JSON vs XML for Unity C# 1 Answer

Distribute terrain in zones 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges