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
3
Question by Richard 3 · May 10, 2011 at 01:40 PM · javascriptxmltutorialsparsing

Easy XML Parsing

I am battling to work / understand XML. Where can I find good clear help or tutorials on the topic? I am working in JavaScript.

Thanks

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

4 Replies

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

Answer by Bunny83 · May 10, 2011 at 03:06 PM

Do you have problems in understanding XML itself or how to read/write it? XML is a really simple but powerful language. Actually there are multiple ways of storing data in it. Some put their data values inside an element as text-node others (like me) prefer to put them as attributes into an element.
Here some example elements:

// a simple element without a body
//<ElementName/>
//
// a normal element with body
//<ElementName> body </ElementName>
//
// another empty element without a body but an attribute
//<ElementName AttributeName="AttributeValue" />

There are some rules you should keep in mind:

  • An xml file can only have one root element. The only exception is the declaration node at the top
  • An xml file should contain a declaration-node at top to specify the character encoding
  • Element or attribute names mustn't contain spaces
  • Attributes are seperated with spaces
  • In most cases the attribute value should be placed in parenthesis.
  • Every element that have been opened have to be closed. Single/empty elements don't need to be closed since they don't have a body section.
  • The body of an element can contain other elements or just text (which counts as textelement)
  • if you want to store text with sensitive characters like "<" "\" ">" they have to be stored inside a CDATA element.
  • A CDATA element looks like: <![CDATA[data goes here]]>


To read or write an xml file there are multiple possibilities. The most common way is to use a DOM-node-tree to represent the xml in memory. Another way (which might be a bit more advanced) is to use a SAX-parser which invokes callback routines for every element it parses.

SAX is great if the file is huge and you don't want to have the whole file as DOM in memory. But in most cases DOM is the easiest way.

In .NET or mono there are some special classes that represents a whole xml file as DOM tree. XmlDocument and XmlElement is what you need.

In JS (in C# as well) you need to include the xml namespace in order to use those classes.

// JS import System.Xml;

// C# using System.Xml;

If you have specific problems just ask ;)

Comment
Add comment · Show 3 · 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 Richard 3 · May 11, 2011 at 06:40 AM 0
Share

Thanks for your help. I am trying to read the 3 values of three nodes in an X$$anonymous$$L file that I receive through loading a URL. One of the three nodes contains a URL for an image I need to load. It is an ad stream from inner-active.com

avatar image Marzoa · Jan 05, 2013 at 03:29 PM 0
Share

Will System.Xml work on every architecture? I mean, in iOS, Android, etc.

avatar image Bunny83 · Jan 06, 2013 at 01:27 AM 0
Share

@$$anonymous$$arzoa: Yes it does, but it adds quite a bit to your filesize. I don't remember the actual size but i think it was around 500$$anonymous$$B.

I used it myself on Android and iOS for my menu system. There are alternatives to System.Xml but some of them lack of some basic features.

Depending on the data you want to store / read you can also use JSON. I've just published my JSON framework. It's very easy to use.

avatar image
8

Answer by CHPedersen · May 10, 2011 at 01:46 PM

I used the XmlReader class to read an XML-file and load the tree into an object I could work with. Is your XML in a file? If so, take a look at this tutorial:

http://msdn.microsoft.com/en-us/library/aa720470%28v=vs.71%29.aspx

If your XML is from a Stream, there's an explanation here:

http://support.microsoft.com/kb/301228

I apologize that these articles are in C# and not JavaScript. The same principles should apply, though.

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
avatar image
3

Answer by $$anonymous$$ · Jan 26, 2012 at 06:54 PM

Unity / XML

http://unitynoobs.blogspot.com/

  • Read

  • Write

  • Encrypting

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
avatar image
1

Answer by loihb · Aug 01, 2012 at 11:51 PM

Save - load script settings from xml

Download :

https://docs.google.com/open?id=0B0aMXRZ2PWXZQjhKMXdDLVJLZDA

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help a noob parse an xml file 1 Answer

Blimp (airship) Script 0 Answers

How should I begin to program an rpg? 1 Answer

Get google account on webgl 0 Answers

C# XML Question 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