1. /* Copyright (C) 2012, Alexei Garbuzenko. All rights reserved.
  2. *
  3. * File: XmlDocument.cs
  4. * Desc: System.Xml.XmlDocument wrapper for Windows Store apps
  5. * Version: 0.04
  6. * Author: Alexei Garbuzenko (Nomad)
  7. *
  8. * Your use and or redistribution of this software in source and / or
  9. * binary form, with or without modification, is subject to your
  10. * ongoing acceptance of and compliance with the terms and conditions of
  11. * agreement with its owner
  12. */
  13. using System.Collections.Generic;
  14. using Windows.Data.Xml.Dom;
  15. using DomXmlDocument = Windows.Data.Xml.Dom.XmlDocument;
  16. namespace System.Xml
  17. {
  18. public class XmlNode
  19. {
  20. protected IXmlNode m_node;
  21. public XmlNodeCollection ChildNodes
  22. {
  23. get { return new XmlNodeCollection(m_node.ChildNodes); }
  24. }
  25. public string Name
  26. {
  27. get { return m_node.NodeName; }
  28. }
  29. public string Value
  30. {
  31. get { return m_node.NodeValue as string; }
  32. }
  33. public string InnerText
  34. {
  35. get { return m_node.InnerText; }
  36. }
  37. public XmlAttributeCollection Attributes
  38. {
  39. get { return new XmlAttributeCollection(m_node.Attributes); }
  40. }
  41. public XmlNode this[string name]
  42. {
  43. get
  44. {
  45. foreach (IXmlNode child in m_node.ChildNodes)
  46. if (child.NodeName == name)
  47. return new XmlNode(child);
  48. return null;
  49. }
  50. }
  51. public XmlNode(IXmlNode node)
  52. {
  53. m_node = node;
  54. }
  55. }
  56. public class XmlAttributeCollection
  57. {
  58. private XmlNamedNodeMap m_attributes;
  59. public XmlNode this[string attribute]
  60. {
  61. get { return GetNamedItem(attribute); }
  62. }
  63. public XmlAttributeCollection(XmlNamedNodeMap attributes)
  64. {
  65. m_attributes = attributes;
  66. }
  67. public XmlNode GetNamedItem(string attribute)
  68. {
  69. IXmlNode node = m_attributes.GetNamedItem(attribute);
  70. if (node == null)
  71. return null;
  72. return new XmlNode(node);
  73. }
  74. }
  75. public class XmlNodeCollection : List<XmlNode>
  76. {
  77. public XmlNodeCollection(XmlNodeList nodes)
  78. {
  79. foreach (IXmlNode node in nodes)
  80. this.Add(new XmlNode(node));
  81. }
  82. }
  83. public class XmlDocument : XmlNode
  84. {
  85. private DomXmlDocument m_document;
  86. private object m_xmlResolver;
  87. public object XmlResolver
  88. {
  89. get { return m_xmlResolver; }
  90. set { m_xmlResolver = value; }
  91. }
  92. public XmlDocument()
  93. : base(new DomXmlDocument())
  94. {
  95. m_document = (DomXmlDocument)m_node;
  96. }
  97. public void LoadXml(string xml)
  98. {
  99. m_document.LoadXml(xml);
  100. }
  101. }
  102. }

System.Xml.XmlDocument wrapper for Windows Store apps

Comments powered by Disqus