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 Jodll · Mar 20, 2012 at 12:41 PM · c#xmlparsinghashtable

Parsing an XML file periodically

Hi everyone,

I'm currently working on a tablet game that needs to parse an XML file, which actually contains a whole database structure (several DB tables). The file is previously loaded to the tablet.

I need to select and return some elements from the XML file periodically -- not at regular intervals, though. In fact, these elements are chosen according to a specific algorithm.

I'm programming in C#, and several ideas came to me, such as:

  • Parsing the XML file with XmlReader every time I need to return elements

  • Parsing the XML file at the beginning of the game only, saving its data to a hashtable, and working with the hashtable each time I'll need to select elements

I could implement the former solution with Linq to XML too, but I've read that XmlReader was the fastest way to parse huge XML files.

The latter solution looks good to me, but I have no idea where to "store" the hashtable (in some cache memory, maybe?).

What would you advise me to do?

Thanks in advance!

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

2 Replies

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

Answer by DaveA · Mar 20, 2012 at 07:01 PM

XmlReader can impact performance (less so with 3.5 thanks to rendering now in a separate thread), but if the data does not change throughout the game, load it at the start and store it. If your game has more than one scene and you need to keep it around, google 'singleton' or just use this: http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html Basically your first scene would load it into some script, and you use that function to say 'don't destroy this game object holding this script' and it will persist across different scenes.

Comment
Add comment · Show 1 · 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 Jodll · Mar 20, 2012 at 07:47 PM 0
Share

Thank you for your answer.

I've read the link you gave, and I think I'll end up using DontDestroyOnLoad. I assume my first scene will parse the X$$anonymous$$L data and save it to a hashtable (or some array). I have a question, though: is there enough RA$$anonymous$$ memory to store all the data? I will be working on iOS and Android.

avatar image
0

Answer by Mike67440 · Mar 26, 2012 at 03:11 PM

Could you not used Liquid XML Editor to parse your xml for you? it also as a built in xml database mapper and a large file editor.

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 Bunny83 · Mar 26, 2012 at 03:13 PM 0
Share

Ehhmm, that's an editor....

This question was about using the xml content in an application / game. He don't want to view or edit the xml. He wants to use it.

avatar image Jodll · Mar 28, 2012 at 06:44 AM 0
Share

Yes, Bunny83 is right. Nonetheless, this editor may be useful for other purposes.

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

I have some issues with implementing polar coordinates written in an Xml File into unity and visualise them afterwards. 0 Answers

C# XML Question 1 Answer

XML parsing c# in unity 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