123 lines
3.8 KiB
C#
123 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
|
|
namespace Sarand.Net.Standard.Data.Xml
|
|
{
|
|
//=======================================================================
|
|
public class SaMsXmlNode : SaErrorStateItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
internal XmlNode node;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
internal SaMsXmlNode (XmlNode node)
|
|
{
|
|
this.node = node;
|
|
}
|
|
protected override void Dispose (bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
node = null;
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
internal XmlDocument OwnerDocument { get { return node != null ? node.OwnerDocument : null; } }
|
|
public String NamespaceURI { get { return node != null ? node.NamespaceURI : ""; } }
|
|
public String Prefix { get { return node != null ? node.Prefix : ""; } }
|
|
//public String Name { get { return node != null ? node.Name : ""; } }
|
|
public String LocalName { get { return node != null ? node.LocalName : ""; } }
|
|
public virtual bool Valid { get { return (node != null); } }
|
|
|
|
//-------------------------------------------------------------------
|
|
// A t t r i b u t e s
|
|
//-------------------------------------------------------------------
|
|
public String GetAttributeValue (String attributeName)
|
|
{
|
|
if (StringUtil.IsEmpty(attributeName) || node == null) return "";
|
|
foreach (XmlAttribute attribute in node.Attributes)
|
|
{
|
|
if (attribute.Name.EqualsCI(attributeName))
|
|
return attribute.Value;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// T e x t
|
|
//-------------------------------------------------------------------
|
|
public String GetText ()
|
|
{
|
|
if (node == null) return "";
|
|
foreach (XmlNode childNode in node.ChildNodes)
|
|
{
|
|
if (childNode.NodeType == XmlNodeType.Text || childNode.NodeType == XmlNodeType.CDATA)
|
|
return childNode.Value;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C h i l d N o d e s
|
|
//-------------------------------------------------------------------
|
|
public List<SaMsXmlNode> GetChildNodes (String name = "")
|
|
{
|
|
List<SaMsXmlNode> childNodes = new List<SaMsXmlNode>();
|
|
if (node == null) return childNodes;
|
|
foreach (XmlNode childNode in node.ChildNodes)
|
|
{
|
|
if (StringUtil.IsEmpty(name) || childNode.Name.EqualsCI(name))
|
|
childNodes.Add(new SaMsXmlNode(childNode));
|
|
}
|
|
return childNodes;
|
|
}
|
|
public bool HasChildNode (String name)
|
|
{
|
|
if (node == null) return false;
|
|
foreach (XmlNode childNode in node.ChildNodes)
|
|
{
|
|
if (StringUtil.IsEmpty(name) || childNode.Name.EqualsCI(name))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
public SaMsXmlNode GetFirstChildNode (String name = "")
|
|
{
|
|
if (node == null) return new SaMsXmlNode(null);
|
|
foreach (XmlNode childNode in node.ChildNodes)
|
|
{
|
|
if (StringUtil.IsEmpty(name) || childNode.Name.EqualsCI(name))
|
|
return new SaMsXmlNode(childNode);
|
|
}
|
|
return new SaMsXmlNode(null);
|
|
}
|
|
public String GetChildText (String name, String defaultValue = "")
|
|
{
|
|
SaMsXmlNode childNode = GetFirstChildNode(name);
|
|
if (childNode != null)
|
|
return childNode.GetText();
|
|
return defaultValue;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
public static class SaMsXmlNodeList
|
|
{
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|