Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add and remove nodes in XML file from script using C# with Unity3D?
    primarykey
    data
    text
    <p>I need to add and remove XML nodes by using C# in Unity3D. In the XML file there are <code>Purchased-Assets</code> and <code>Unbought-Assets</code>. When a button is clicked, I want to remove a named <code>UnPurchased-Asset</code> from the <code>Unbought-Assets</code> node and add this item to <code>Purchased-Assets</code> as a <code>Purchased-Asset</code>. I don't have any idea where to start.</p> <p>Code so far (C#):</p> <pre><code>using UnityEngine; using System.Collections; using System.Xml; using System.IO; public class MyAppStuffCode : MonoBehaviour { XmlDocument xml; public XmlNodeList _name; //Used to load XML file. xml = new XmlDocument(); xml.Load(Application.dataPath + "/Resources/MyAppStuffXml.xml"); // Use this for initialization void Start () { } // Update is called once per frame void Update () { } public void OnButtonClicked(string BName) { // Code to add/remove XML nodes here! } } </code></pre> <p>Example XML file:</p> <pre><code>&lt;TreasureChart&gt; &lt;Dudes&gt; &lt;Rapper&gt; &lt;!-- Purchased assets --&gt; &lt;Purchased-Assets&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;BackTalk&lt;/Name&gt; &lt;ID&gt;A&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;Beard&lt;/Name&gt; &lt;ID&gt;B&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;IntroRap&lt;/Name&gt; &lt;ID&gt;C&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;Moustache&lt;/Name&gt; &lt;ID&gt;D&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;MyFaceDudeRap&lt;/Name&gt; &lt;ID&gt;E&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;Purchased-Asset&gt; &lt;Name&gt;MyFaceMyRap&lt;/Name&gt; &lt;ID&gt;F&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/Purchased-Asset&gt; &lt;/Purchased-Assets&gt; &lt;!-- Unbought assets --&gt; &lt;Unbought-Assets&gt; &lt;UnPurchased-Asset&gt; &lt;Name&gt;Share&lt;/Name&gt; &lt;ID&gt;D&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/UnPurchased-Asset&gt; &lt;UnPurchased-Asset&gt; &lt;Name&gt;SunGlasses&lt;/Name&gt; &lt;ID&gt;E&lt;/ID&gt; &lt;Points&gt;20&lt;/Points&gt; &lt;/UnPurchased-Asset&gt; &lt;/Unbought-Assets&gt; &lt;/Rapper&gt; &lt;/Dudes&gt; &lt;/TreasureChart&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload