Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ina · Aug 30, 2011 at 08:51 AM · wwwxmldata.net

Loading a large xml file (~200 multi-level nodes) into Unity

I'm trying to load a large xml file in for parsing from www.text, but the usual xml.LoadXml() does not work...

I've also tried:

var stringReader:StringReader = new StringReader(w.text); stringReader.Read(); // skip BOM

 xml.LoadXml(stringReader.ReadToEnd());

I still get the following error:

XmlException: Text node cannot appear in this state.  Line 1, position 1.
Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace)
Mono.Xml2.XmlTextReader.ReadContent ()
Mono.Xml2.XmlTextReader.Read ()
System.Xml.XmlTextReader.Read ()
System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader)
System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader)
System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader)
System.Xml.XmlDocument.LoadXml (System.String xml)
gniptwitter+$fetchTweets$42+$.MoveNext () (at /gniptwitter.js:35)

The data file is from an api so I can't change its format. However, it is valid XML. It might be UTF8 or some odd encoding that's causing Unity to balk at XML-parsing it...

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 Waz · Aug 30, 2011 at 10:30 AM 0
Share

Does it actual have a Byte Order $$anonymous$$arker? I'd start by not doing that extra read.

avatar image ina · Aug 31, 2011 at 07:25 AM 0
Share

i actually tried it straight on with loadX$$anonymous$$L without that .read ... but errors galore. google'd around, found that the .read worked for some, but apparently not here :-\

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CHPedersen · Aug 30, 2011 at 09:51 AM

This does happen due to encoding issues; if you use a standard textreader and read one character at a time and then print the characters, you'll notice that the stream is littered with spaces and possibly questionmarks if the StringReader fails to decode it. If your xml is in a file on the harddrive, the usual way to load it is to call XmlDocument.Load. Not XmlDocument.LoadXml, mind you. XmlDocument.Load takes care of parsing the XML for you, while XmlDocument.LoadXml expects a string that contains raw XML to make a tree out of.

In your case, where a file is very large, calling XmlDocument.Load from the mainthread will cause the thread to block until loading completes, and you'll experience a holdup in Unity's rendering. To get around that, you can have a separate thread load the xml for you and signal the mainthread when it's complete, or you can streamread the XML (using an XmlReader), and only call its Read()-method a few times every frame.

Comment
Add comment · Show 7 · 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 Waz · Aug 30, 2011 at 10:29 AM 0
Share

200 nodes is tiny, so I doubt a thread is needed.

avatar image CHPedersen · Aug 30, 2011 at 10:59 AM 0
Share

He says "200 multi-level nodes". I assume this means each one has multiple children and grandchildren of its own.

avatar image Waz · Aug 30, 2011 at 11:04 AM 0
Share

That wouldn't be valid X$$anonymous$$L then, since there can be only one root node. (rimshot!)

avatar image CHPedersen · Aug 30, 2011 at 11:13 AM 0
Share

Oh, you're such a nitpicker, Warwick. :)

avatar image ina · Aug 31, 2011 at 07:31 AM 0
Share

1) i am not sure if it is the loading being blocked, as would loading being blocked result in a red-marked error in the console, as pasted above? 2) and, i'm not sure how to load the separate threads - would calling yield on the loadXml work? (@warwick and apologies, i often use words loosely, but the meaning is there! ;) )

Show more comments

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Guys please help me!!how to download xml file from url in android device runtime 1 Answer

Load Xml on Android with XmlReader 2 Answers

web page html parsing 1 Answer

How to read local XML file on iOS? 1 Answer

Best way to convert data into variables from a www request? 0 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