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 /
avatar image
0
Question by nypraise · Mar 14, 2014 at 03:22 PM · iosxcodesavexmlread

XmlException when trying to read/write XML from iOS device

I am trying to read and write XML to iOS. Everything works fine in the iOS simulation, but when I try to build an app on my device the problems seems to be starting.

I have added the xml file to Copy Bundle Resources with "Copy items into destination group´s folder (if needed) check and "Create groups for any added folders" checked.

This is my code for loading the XML file :

 string path = path = Application.persistentDataPath + "/gamexmldata.txt";
 
 public void LoadFromXml()
 {
 Debug.Log ("Du nådde LoadXML metoden");
 
 
 XmlDocument xmlDoc = new XmlDocument();
 
 if(File.Exists(path))
 {
 Debug.Log("Filen finnes");
 Debug.Log(path.ToString());
 xmlDoc.Load(path);
 
 
 XmlNodeList transformList = xmlDoc.GetElementsByTagName("rotation");
 
 foreach (XmlNode transformInfo in transformList)
 {
 XmlNodeList transformcontent = transformInfo.ChildNodes;
 
 foreach (XmlNode transformItens in transformcontent)
 {
 if(transformItens.Name == "x")
 {
 
 Debug.Log(transformItens.InnerText);
 resultatFraXML += transformItens.InnerText;
 }
 if(transformItens.Name == "y")
 {
 
 Debug.Log(transformItens.InnerText);
 resultatFraXML += transformItens.InnerText;
 }
 if(transformItens.Name == "z")
 {
 Debug.Log(transformItens.InnerText);
 
 resultatFraXML += transformItens.InnerText;
 }
 if(transformItens.Name == "name")
 {
 resultatFraXML += transformItens.InnerText;
 guitext.text = resultatFraXML;
 GameControl.control.outputXml = resultatFraXML;
 Debug.Log(resultatFraXML);
 }
 
 }
 }
 
 }
 
 }
 

The error I get is :

 XmlException: Document element did not appear. file:///var/mobile/Applications/47C26549-9CB0-46C2-9906-66399A5E515C/Documents/gamexmldata.txt Line 1, position 1.
 at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
 at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0 
 at Mono.Xml.EntityResolvingXmlReader.Read () [0x00000] in <filename unknown>:0 
 at Mono.Xml.DTDValidatingReader.ReadContent () [0x00000] in <filename unknown>:0 
 at Mono.Xml.DTDValidatingReader.Read () [0x00000] in <filename unknown>:0 
 at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00000] in <filename unknown>:0 
 at System.Xml.XmlValidatingReader.Read () [0x00000] in <filename unknown>:0 
 at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
 at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0 
 at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) [0x00000] in <filename unknown>:0 
 at System.Xml.XmlDocument.Load (System.String filename) [0x00000] in <filename unknown>:0 
 at ReadXmlData.LoadFromXml () [0x00000] in <filename unknown>:0 
 at ReadXmlData.Start () [0x00000] in <filename unknown>:0 
 
 (Filename: Line: -1)
 

I was thinking it might be UTF-8 and BOM problems, but I have done all converting and checking etc. Can´t find any BOM at all.

By accident the same error came when I played around with the Unity editor and then it appeared that the file was empty. Earlier on my debugging I did a File.Create in the code. Could it be that I have a empty file in the app that has NO data in it all? Or is the file placed in a wrong directory?

Any good ideas to why I get this kind of error?

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Mar 14, 2014 at 03:25 PM 0
Share

Yes, I reckon your X$$anonymous$$L file contains no text. The reason I say this, is that if I work backwards through the call stack I can see your Start() calls LoadFromX$$anonymous$$L(), which calls Load, then the xml reading code drills down and ends up in $$anonymous$$ono.Xml2.XmlTextReader.Read(). The error message says that row 0, column 0 was where the problem happened, so I guess that no data could be read.

avatar image Tasmia · Apr 18, 2014 at 07:33 AM 0
Share
 if(!System.IO.File.Exists(Application.persistentDataPath+"/PlayerData.xml"))
         {
             //copy resource file to persistent path
             System.IO.File.WriteAllText(Application.persistentDataPath+"/PlayerData.xml",textX$$anonymous$$L.text);
             xmlP.Load(Application.persistentDataPath+"/PlayerData.xml");
         }
         else
         {
             xmlP.Load(Application.persistentDataPath+"/PlayerData.xml");
         }


textX$$anonymous$$L is public textAsset filled with resource folder file

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tasmia · Apr 10, 2014 at 10:21 AM

 string path = path = Application.persistentDataPath + "/gamexmldata.xml";

replace your extension and try again

Comment
Add comment · 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

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

iOS PlayerPrefs issue, Working on Desktop Not on iOS device (5.1) 0 Answers

how can i take a screenshot (by UiButton) and save it in CameraRoll (Gallery in iOS)? 0 Answers

Saving My World 1 Answer

the XML file doesn't work when i install the app from the app store 0 Answers

Write and Read to a iOS device! Help 1 Answer


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