Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- using System.Xml;
- public class CommsTest : MonoBehaviour
- {
- void Start()
- {
- ProcessXML(@" <Authors>
- <Author>
- <FirstName>John</FirstName>
- <LastName>Doe</LastName>
- <Age>30</Age>
- </Author>
- <Author>
- <FirstName>Jane</FirstName>
- <LastName>Doe</LastName>
- <Age>20</Age>
- </Author>
- </Authors> ");
- }
- void ProcessXML(string xmlText)
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(xmlText);
- XmlNodeReader xml = new XmlNodeReader(doc);
- ProcessXMLNode(doc.ReadNode(xml),0);
- }
- void ProcessXMLNode(XmlNode node, int depth)
- {
- string indent = new String(' ',depth*4);
- Debug.Log(indent+"Xml Node Name: "+node.Name);
- Debug.Log(indent+"Xml Node Value: "+node.Value);
- Debug.Log(indent+"Xml Attributes: "+node.Attributes.Count);
- foreach (XmlAttribute a in node.Attributes) {
- Debug.Log(indent+" attribute: "+a);
- }
- Debug.Log(indent+"Xml ChildNodes: "+node.ChildNodes.Count);
- foreach (XmlNode n in node.ChildNodes)
- {
- ProcessXMLNode(n, depth+1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment