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 YikYikHeiHei · Aug 13, 2011 at 01:58 AM · xml

How to write a Xml file better?

I went to write a xml file to place the object transform, but I don't know how to write it.

Can anyone help me?

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

3 Replies

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

Answer by $$anonymous$$ · Aug 14, 2011 at 08:58 AM

Try this:

 public void WriteToXml()  
 {  
     
   string filepath = Application.dataPath + @"/StreamingAssets/gamexmldata.xml";  
   XmlDocument xmlDoc = new XmlDocument();  
     
   if(File.Exists (filepath))  
   {  
    xmlDoc.Load(filepath);  
      
    XmlElement elmRoot = xmlDoc.DocumentElement;  
      
     elmRoot.RemoveAll(); // remove all inside the transforms node.  
      
     XmlElement elmNew = xmlDoc.CreateElement("rotation"); // create the rotation node.  
      
      XmlElement rotation_X = xmlDoc.CreateElement("x"); // create the x node.  
       rotation_X.InnerText = x; // apply to the node text the values of the variable.  
      
      XmlElement rotation_Y = xmlDoc.CreateElement("y"); // create the y node.  
       rotation_Y.InnerText = y; // apply to the node text the values of the variable.  
      
      XmlElement rotation_Z = xmlDoc.CreateElement("z"); // create the z node.  
       rotation_Z.InnerText = z; // apply to the node text the values of the variable.  
      
    elmNew.AppendChild(rotation_X); // make the rotation node the parent.  
    elmNew.AppendChild(rotation_Y); // make the rotation node the parent.  
    elmNew.AppendChild(rotation_Z); // make the rotation node the parent.  
    elmRoot.AppendChild(elmNew); // make the transform node the parent.  
      
    xmlDoc.Save(filepath); // save file.  
   }  
  } 

This code takes only the values ​​of rotation, but you can create other nodes and store what you want.

Full code in http://unitynoobs.blogspot.com/

Comment
Add comment · Show 4 · 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 14, 2011 at 12:01 PM 0
Share

That's the DO$$anonymous$$ way to do it. Plain XmlWriter is simpler of course. Why is it wherever I see X$$anonymous$$L, I also see over-engineering? It was once such a simple thing.

avatar image YikYikHeiHei · Aug 15, 2011 at 01:06 AM 0
Share

Thanks! I will try it!

avatar image Kalu · Sep 01, 2011 at 08:27 AM 0
Share

"XmlDocument" => the type or namespace name could not be found. What wrong? I just c/c your code...

avatar image $$anonymous$$ · Sep 01, 2011 at 11:41 AM 0
Share

Try download the full project https://sites.google.com/site/unitynoobs2/unity-noobs/xmldatawriter.zip?attredirects=0&d=1

avatar image
1

Answer by SmoothCurves · Aug 13, 2011 at 02:31 AM

,How good are you at scripts? A while ago I posted a how too on the pennymo blog http://pennymo.com/2009/11/21/xml-and-unity-3d/

At that time the xml export functions where only accessible from C#, apparently you can do it all from javascript.

And remember you can't write a local file from the web player.

And, for lots more helpful info use this google query "XML write site:unity3d.com"

--Smooth

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 YikYikHeiHei · Aug 13, 2011 at 02:35 AM 0
Share

I went to write a xml file not write the unity script...

avatar image
0

Answer by Waz · Aug 14, 2011 at 12:17 AM

If you mean:

How do I write the object transform into an XML file?

then you can write (and later read) the component values:

 localPosition
 localRotation
 localScale

you also need to set the parent, though you'll probably derive that at read time from the XML structure.

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 YikYikHeiHei · Aug 14, 2011 at 04:36 AM 0
Share

Have you a X$$anonymous$$L file sample? I not kwon how to write it. Thanks!

avatar image Waz · Aug 14, 2011 at 07:06 AM 0
Share

Of what? Do you know how to write a float to a file? If so, consider that each of the above is just 3 or 4 floats.

avatar image hesa2020 · Jun 26, 2012 at 02:53 PM 0
Share

Try : string NewString = OTHERFLOAT.ToString(); And then try to convert it back to float

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

6 People are following this question.

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

Related Questions

Using XML for a simple webplayer Highscore Table 1 Answer

Work with XML hidden for the user? 1 Answer

Write to XML-file within Assets\Resources 1 Answer

Editing an XML File 1 Answer

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