|
using System;
namespace Puma.Xml
{
public class XmlXsdNode : XmlXsdNodeBuilder
{
internal XmlXsdNode(System.Xml.Schema.XmlSchemaElement XmlSchemaElement, object ParentObject)
{
if (ParentObject is XmlXsdDocument)
{
XmlXsdDocument = (XmlXsdDocument)ParentObject;
}
else
{
XmlXsdDocument = ((XmlXsdNode)ParentObject).XmlXsdDocument;
}
_parent = ParentObject;
_xsdNode = new XsdNode(XmlSchemaElement, this);
base.SetChildSchemaElements(XsdNode.GetChildSchemaElements(XmlSchemaElement));
}
private Puma.Xml.XmlNode _xmlNode;
private Puma.Xml.XsdNode _xsdNode;
private object _parent;
internal void SetXmlNode(System.Xml.XmlElement XmlElement)
{
_xmlNode = new XmlNode(XmlElement, this);
this.BuildingComplete();
}
internal void ReleaseXmlNode()
{
_xmlNode = null;
}
public readonly Puma.Xml.XmlXsdDocument XmlXsdDocument;
public Puma.Xml.XmlNode XmlNode
{
get
{
return _xmlNode;
}
}
public Puma.Xml.XsdNode XsdNode
{
get
{
return _xsdNode;
}
}
public object Parent
{
get
{
return _parent;
}
}
internal XmlXsdNode SafetyParentNode {get {return Parent == null ? null : Parent as XmlXsdNode;} }
private void BuildingComplete()
{
if (this.XmlXsdDocument.NodeExtensible != null)
{
this.XsdNode.SetTagEx(this.XmlXsdDocument.NodeExtensible.OnXsdNodeCreated(XsdNode));
this.XmlNode.SetTagEx(this.XmlXsdDocument.NodeExtensible.OnXmlNodeCreated(XmlNode));
this.SetTagEx(this.XmlXsdDocument.NodeExtensible.OnXmlXsdNodeCreated(this));
}
}
#region Convinets
public string Name
{
get
{
return _xsdNode.XmlSchemaElement.Name;
}
}
public bool IsComplexType
{
get
{
return _xsdNode.IsComplexType;
}
}
public string Value
{
get
{
if (IsComplexType) return null;
return _xmlNode.XmlElement.InnerText;
}
set
{
if (IsComplexType) throw new Puma.Xml.XmlExceptions.InvalidRequireException(Puma.Xml.XmlExceptions.InvalidRequireExceptionCode.ValueOnComplexType);
_xmlNode.XmlElement.InnerText = value;
}
}
public object TypedValue
{
get
{
if (IsComplexType) return null;
if (XsdNode != null)
{
if (this.XsdNode.XsdSimpleType.ValueType == typeof(string))
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(Value);
return sb.ToString();
}
else
{
System.Reflection.MethodInfo methodInfo = XsdNode.XsdSimpleType.ValueType.GetMethod("Parse", new System.Type[] { typeof(string) });
if (methodInfo != null)
{
return methodInfo.Invoke(new object(), new object[] { Value });
}
else
{
return null;
}
}
}
else
{
return null;
}
}
set
{
if (IsComplexType) throw new Puma.Xml.XmlExceptions.InvalidRequireException(Puma.Xml.XmlExceptions.InvalidRequireExceptionCode.ValueOnComplexType);
Value = value.ToString();
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.