- /* Copyright (C) 2012, Alexei Garbuzenko. All rights reserved.
- *
- * File: XmlDocument.cs
- * Desc: System.Xml.XmlDocument wrapper for Windows Store apps
- * Version: 0.04
- * Author: Alexei Garbuzenko (Nomad)
- *
- * Your use and or redistribution of this software in source and / or
- * binary form, with or without modification, is subject to your
- * ongoing acceptance of and compliance with the terms and conditions of
- * agreement with its owner
- */
- using System.Collections.Generic;
- using Windows.Data.Xml.Dom;
- using DomXmlDocument = Windows.Data.Xml.Dom.XmlDocument;
- namespace System.Xml
- {
- public class XmlNode
- {
- protected IXmlNode m_node;
- public XmlNodeCollection ChildNodes
- {
- get { return new XmlNodeCollection(m_node.ChildNodes); }
- }
- public string Name
- {
- get { return m_node.NodeName; }
- }
- public string Value
- {
- get { return m_node.NodeValue as string; }
- }
- public string InnerText
- {
- get { return m_node.InnerText; }
- }
- public XmlAttributeCollection Attributes
- {
- get { return new XmlAttributeCollection(m_node.Attributes); }
- }
- public XmlNode this[string name]
- {
- get
- {
- foreach (IXmlNode child in m_node.ChildNodes)
- if (child.NodeName == name)
- return new XmlNode(child);
- return null;
- }
- }
- public XmlNode(IXmlNode node)
- {
- m_node = node;
- }
- }
- public class XmlAttributeCollection
- {
- private XmlNamedNodeMap m_attributes;
- public XmlNode this[string attribute]
- {
- get { return GetNamedItem(attribute); }
- }
- public XmlAttributeCollection(XmlNamedNodeMap attributes)
- {
- m_attributes = attributes;
- }
- public XmlNode GetNamedItem(string attribute)
- {
- IXmlNode node = m_attributes.GetNamedItem(attribute);
- if (node == null)
- return null;
- return new XmlNode(node);
- }
- }
- public class XmlNodeCollection : List<XmlNode>
- {
- public XmlNodeCollection(XmlNodeList nodes)
- {
- foreach (IXmlNode node in nodes)
- this.Add(new XmlNode(node));
- }
- }
- public class XmlDocument : XmlNode
- {
- private DomXmlDocument m_document;
- private object m_xmlResolver;
- public object XmlResolver
- {
- get { return m_xmlResolver; }
- set { m_xmlResolver = value; }
- }
- public XmlDocument()
- : base(new DomXmlDocument())
- {
- m_document = (DomXmlDocument)m_node;
- }
- public void LoadXml(string xml)
- {
- m_document.LoadXml(xml);
- }
- }
- }
System.Xml.XmlDocument wrapper for Windows Store apps