duck

duck

Jun 4th, 2010
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.21 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. using System.Xml;
  5.  
  6. public class CommsTest : MonoBehaviour
  7. {
  8.  
  9.     void Start()
  10.     {
  11.         ProcessXML(@" <Authors>
  12. <Author>
  13. <FirstName>John</FirstName>
  14. <LastName>Doe</LastName>
  15. <Age>30</Age>
  16. </Author>
  17. <Author>
  18. <FirstName>Jane</FirstName>
  19. <LastName>Doe</LastName>
  20. <Age>20</Age>
  21. </Author>
  22. </Authors> ");
  23.     }
  24.  
  25.  
  26.     void ProcessXML(string xmlText)
  27.     {
  28.         XmlDocument doc = new XmlDocument();
  29.         doc.LoadXml(xmlText);
  30.  
  31.         XmlNodeReader xml = new XmlNodeReader(doc);
  32.  
  33.         ProcessXMLNode(doc.ReadNode(xml),0);
  34.  
  35.     }
  36.  
  37.     void ProcessXMLNode(XmlNode node, int depth)
  38.     {
  39.         string indent = new String(' ',depth*4);
  40.  
  41.         Debug.Log(indent+"Xml Node Name: "+node.Name);
  42.         Debug.Log(indent+"Xml Node Value: "+node.Value);
  43.         Debug.Log(indent+"Xml Attributes: "+node.Attributes.Count);
  44.         foreach (XmlAttribute a in node.Attributes) {
  45.             Debug.Log(indent+" attribute: "+a);
  46.         }
  47.         Debug.Log(indent+"Xml ChildNodes: "+node.ChildNodes.Count);
  48.         foreach (XmlNode n in node.ChildNodes)
  49.         {
  50.             ProcessXMLNode(n, depth+1);
  51.         }
  52.     }
  53.            
  54. }
Advertisement
Add Comment
Please, Sign In to add comment