public XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName name = this.entries[hashCode & this.mask]; name != null; name = name.next) { if ((((name.HashCode == hashCode) && ((name.LocalName == localName) || name.LocalName.Equals(localName))) && ((name.Prefix == prefix) || name.Prefix.Equals(prefix))) && (((name.NamespaceURI == ns) || name.NamespaceURI.Equals(ns)) && name.Equals(schemaInfo))) { return name; } } prefix = this.nameTable.Add(prefix); localName = this.nameTable.Add(localName); ns = this.nameTable.Add(ns); int index = hashCode & this.mask; XmlName name2 = XmlName.Create(prefix, localName, ns, hashCode, this.ownerDocument, this.entries[index], schemaInfo); this.entries[index] = name2; if (this.count++ == this.mask) { this.Grow(); } return name2; }
public XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = _entries[hashCode & _mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } return null; }
public static XmlName Create(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next, IXmlSchemaInfo schemaInfo) { if (schemaInfo == null) { return new XmlName(prefix, localName, ns, hashCode, ownerDoc, next); } else { return new XmlNameEx(prefix, localName, ns, hashCode, ownerDoc, next, schemaInfo); } }
internal XmlNameEx(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next, IXmlSchemaInfo schemaInfo) : base(prefix, localName, ns, hashCode, ownerDoc, next) { this.SetValidity(schemaInfo.Validity); this.SetIsDefault(schemaInfo.IsDefault); this.SetIsNil(schemaInfo.IsNil); this.memberType = schemaInfo.MemberType; this.schemaType = schemaInfo.SchemaType; this.decl = (schemaInfo.SchemaElement != null) ? ((object) schemaInfo.SchemaElement) : ((object) schemaInfo.SchemaAttribute); }
internal LineInfo(XmlReader reader) { IXmlLineInfo li = reader as IXmlLineInfo; if (li != null) { this.line = li.LineNumber; this.col = li.LinePosition; this.baseUri = reader.BaseURI; this.info = reader.SchemaInfo; } }
internal XmlSchemaInfo (IXmlSchemaInfo info) { isDefault = info.IsDefault; isNil = info.IsNil; memberType = info.MemberType; attr = info.SchemaAttribute; elem = info.SchemaElement; type = info.SchemaType; validity = info.Validity; }
protected XPathNavigatorReader(XPathNavigator navToRead, IXmlLineInfo xli, IXmlSchemaInfo xsi) { this.navToRead = navToRead; this.lineInfo = xli; this.schemaInfo = xsi; this.nav = XmlEmptyNavigator.Singleton; this.state = State.Initial; this.depth = 0; this.nodeType = ToXmlNodeType(this.nav.NodeType); }
public bool Validate(XmlNode nodeToValidate) { XmlSchemaObject? partialValidationType = null; XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.AllowXmlAttributes; Debug.Assert(nodeToValidate.SchemaInfo != null); _startNode = nodeToValidate; switch (nodeToValidate.NodeType) { case XmlNodeType.Document: validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints; break; case XmlNodeType.DocumentFragment: break; case XmlNodeType.Element: //Validate children of this element IXmlSchemaInfo schemaInfo = nodeToValidate.SchemaInfo; XmlSchemaElement?schemaElement = schemaInfo.SchemaElement; if (schemaElement != null) { if (!schemaElement.RefName.IsEmpty) { //If it is element ref, partialValidationType = _schemas.GlobalElements[schemaElement.QualifiedName]; //Get Global element with correct Nillable, Default etc } else { //local element partialValidationType = schemaElement; } //Verify that if there was xsi:type, the schemaElement returned has the correct type set Debug.Assert(schemaElement.ElementSchemaType == schemaInfo.SchemaType); } else { //Can be an element that matched xs:any and had xsi:type partialValidationType = schemaInfo.SchemaType; if (partialValidationType == null) { //Validated against xs:any with pc= lax or skip or undeclared / not validated element if (nodeToValidate.ParentNode !.NodeType == XmlNodeType.Document) { //If this is the documentElement and it has not been validated at all nodeToValidate = nodeToValidate.ParentNode; } else { partialValidationType = FindSchemaInfo((nodeToValidate as XmlElement) !); if (partialValidationType == null) { throw new XmlSchemaValidationException(SR.XmlDocument_NoNodeSchemaInfo, null, nodeToValidate); } } } } break;
public static bool FnNilled(XPathNavigator arg) { if (arg == null) { throw new XmlQueryException("Function nilled() does not allow empty sequence parameter."); } IXmlSchemaInfo info = arg.NodeType == XPathNodeType.Element ? arg.SchemaInfo : null; return(info != null && info.IsNil); }
public static XmlSchema GetSchema(this IXmlSchemaInfo schemaInfo) { var schemaType = schemaInfo.SchemaType; if (schemaType == null) { throw new InvalidOperationException("Schema info does not have a schema type."); } return(schemaType.Parent.GetSchema()); }
protected XPathNavigatorReader(XPathNavigator navToRead, IXmlLineInfo xli, IXmlSchemaInfo xsi) { // Need clone that can be moved independently of original navigator this.navToRead = navToRead; this.lineInfo = xli; this.schemaInfo = xsi; this.nav = XmlEmptyNavigator.Singleton; this.state = State.Initial; this.depth = 0; this.nodeType = XPathNavigatorReader.ToXmlNodeType(this.nav.NodeType); }
public static string ExpandName(this IXmlSchemaInfo schemaInfo, string qualifiedName) { var names = qualifiedName.Split(':'); if (names.Length == 2) { var ns = schemaInfo.GetNamespace(names[0]); return(String.Format("{0}:{1}", ns, names[1])); } return(qualifiedName); }
public static XPathNavigatorReader Create(XPathNavigator navToRead) { XPathNavigator navigator = navToRead.Clone(); IXmlLineInfo xli = navigator as IXmlLineInfo; IXmlSchemaInfo xsi = navigator as IXmlSchemaInfo; if (xsi == null) { return(new XPathNavigatorReader(navigator, xli, xsi)); } return(new XPathNavigatorReaderWithSI(navigator, xli, xsi)); }
public SequenceType(XmlTypeCode typeCode, IXmlSchemaInfo schemaInfo, Type clrType) { TypeCode = typeCode; NameTest = XmlQualifiedNameTest.Wildcard; Cardinality = XmlTypeCardinality.One; SchemaType = schemaInfo.SchemaType; SchemaElement = schemaInfo.SchemaElement; SchemaAttribute = schemaInfo.SchemaAttribute; ParameterType = clrType; IsNode = TypeCodeIsNodeType(TypeCode); ItemType = TypeCodeToItemType(TypeCode, SchemaType); }
private static XElement NormalizeElement(XElement element, bool havePsvi) { if (havePsvi) { IXmlSchemaInfo schemaInfo = element.GetSchemaInfo(); XmlSchemaType schemaType = schemaInfo != null ? schemaInfo.SchemaType : null; XmlTypeCode? typeCode = schemaType != null ? schemaType.TypeCode : (XmlTypeCode?)null; switch (typeCode) { case XmlTypeCode.Boolean: return(new XElement(element.Name, NormalizeAttributes(element, true), (bool)element)); case XmlTypeCode.DateTime: return(new XElement(element.Name, NormalizeAttributes(element, true), (DateTime)element)); case XmlTypeCode.Decimal: return(new XElement(element.Name, NormalizeAttributes(element, true), (decimal)element)); case XmlTypeCode.Double: return(new XElement(element.Name, NormalizeAttributes(element, true), (double)element)); case XmlTypeCode.Float: return(new XElement(element.Name, NormalizeAttributes(element, true), (float)element)); case XmlTypeCode.HexBinary: case XmlTypeCode.Language: return(new XElement(element.Name, NormalizeAttributes(element, true), ((string)element).ToLower())); default: return(new XElement(element.Name, NormalizeAttributes(element, true), element.Nodes().Select(n => NormalizeNode(n, true)))); } } return(new XElement(element.Name, NormalizeAttributes(element, false), element.Nodes().Select(n => NormalizeNode(n, false)))); }
public object isId() { IXmlSchemaInfo schema_info = XmlNode.SchemaInfo; if (schema_info != null) { return(schema_info.SchemaType.TypeCode == XmlTypeCode.Id); } else { return(false); } }
static XmlSchemaInfo CopySchemaInfo(IXmlSchemaInfo src) { return(new XmlSchemaInfo() { IsDefault = src.IsDefault, IsNil = src.IsNil, MemberType = src.MemberType, SchemaAttribute = src.SchemaAttribute, SchemaElement = src.SchemaElement, SchemaType = src.SchemaType, Validity = src.Validity }); }
private XmlAttribute LoadAttributeNode() { Debug.Assert(_reader.NodeType == XmlNodeType.Attribute); XmlReader r = _reader; if (r.IsDefault) { return(LoadDefaultAttribute()); } XmlAttribute attr = _doc.CreateAttribute(r.Prefix, r.LocalName, r.NamespaceURI); IXmlSchemaInfo schemaInfo = r.SchemaInfo; if (schemaInfo != null) { attr.XmlName = _doc.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, schemaInfo); } while (r.ReadAttributeValue()) { XmlNode node; switch (r.NodeType) { case XmlNodeType.Text: node = _doc.CreateTextNode(r.Value); break; case XmlNodeType.EntityReference: node = _doc.CreateEntityReference(r.LocalName); if (r.CanResolveEntity) { r.ResolveEntity(); LoadAttributeValue(node, false); // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true, // if the reader does not present any children for the ent-ref if (node.FirstChild == null) { node.AppendChildForLoad(_doc.CreateTextNode(string.Empty), _doc); } } break; default: throw UnexpectedNodeType(r.NodeType); } Debug.Assert(node != null); attr.AppendChildForLoad(node, _doc); } return(attr); }
private static XElement NormalizeElement(XElement element, bool havePSVI) { if (havePSVI) { IXmlSchemaInfo dt = element.GetSchemaInfo(); switch (dt.SchemaType.TypeCode) { case XmlTypeCode.Boolean: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), (bool)element)); case XmlTypeCode.DateTime: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), (DateTime)element)); case XmlTypeCode.Decimal: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), (decimal)element)); case XmlTypeCode.Double: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), (double)element)); case XmlTypeCode.Float: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), (float)element)); case XmlTypeCode.HexBinary: case XmlTypeCode.Language: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), ((string)element).ToLower())); default: return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), element.Nodes().Select(n => NormalizeNode(n, havePSVI)) )); } } return(new XElement(element.Name, NormalizeAttributes(element, havePSVI), element.Nodes().Select(n => NormalizeNode(n, havePSVI)) )); }
public override bool Equals(IXmlSchemaInfo schemaInfo) { if (schemaInfo != null && schemaInfo.Validity == (XmlSchemaValidity)(_flags & ValidityMask) && schemaInfo.IsDefault == ((_flags & IsDefaultBit) != 0) && schemaInfo.IsNil == ((_flags & IsNilBit) != 0) && (object)schemaInfo.MemberType == (object)_memberType && (object)schemaInfo.SchemaType == (object)_schemaType && (object)schemaInfo.SchemaElement == (object)(_decl as XmlSchemaElement) && (object)schemaInfo.SchemaAttribute == (object)(_decl as XmlSchemaAttribute)) { return(true); } return(false); }
private ObservableCollection <XmlDocumentSchemaAttribute> GetPossibleAttributes(XElement xe) { ObservableCollection <XmlDocumentSchemaAttribute> a = new ObservableCollection <XmlDocumentSchemaAttribute>(); IXmlSchemaInfo ixsi = xe.GetSchemaInfo(); if (ixsi != null) { XmlSchemaType xst = ixsi.SchemaType; if (xst is XmlSchemaComplexType) { XmlSchemaComplexType xsct = (XmlSchemaComplexType)xst; // alle im schema spezifizierten attribute zum editieren hinzufügen foreach (XmlSchemaAttribute xsa in xsct.AttributeUses.Values) { a.Add(new XmlDocumentSchemaAttribute(a, xe, xsa)); } // alle attribute im dokument, die nicht im schema spezifiziert sind hinzufügen foreach (XAttribute xa in xe.Attributes()) { IXmlSchemaInfo i = xa.GetSchemaInfo(); if (i == null || i.SchemaAttribute == null) { if (xa.Name.Namespace == string.Empty && xa.Name.LocalName != "xmlns") { a.Add(new XmlDocumentSchemaAttribute(a, xe, xa.Name)); } } } } } else { // kein schema geladen, alles aus dem dokument foreach (XAttribute xa in xe.Attributes()) { if (xa.Name.Namespace == string.Empty && xa.Name.LocalName != "xmlns") { a.Add(new XmlDocumentSchemaAttribute(a, xe, xa.Name)); } } } return(a); }
public object nilled(XPathNodeIterator iter) { // fn:nilled($arg as node()?) as xs:boolean? XPathNavigator node = ExtensionObjectConvert.ToXPathNavigator(iter); if (node == null || node.NodeType != XPathNodeType.Element) { return(ExtensionObjectConvert.EmptyIterator); } IXmlSchemaInfo schemaInfo = node.SchemaInfo; return(schemaInfo != null && schemaInfo.IsNil); }
//Code for finding type during partial validation private XmlSchemaObject FindSchemaInfo(XmlElement elementToValidate) { _isPartialTreeValid = true; Debug.Assert(elementToValidate.ParentNode.NodeType != XmlNodeType.Document); //Handle if it is the documentElement separately //Create nodelist to navigate down again XmlNode currentNode = elementToValidate; IXmlSchemaInfo parentSchemaInfo = null; int nodeIndex = 0; //Check common case of parent node first XmlNode parentNode = currentNode.ParentNode; do { parentSchemaInfo = parentNode.SchemaInfo; if (parentSchemaInfo.SchemaElement != null || parentSchemaInfo.SchemaType != null) { break; //Found ancestor with schemaInfo } CheckNodeSequenceCapacity(nodeIndex); _nodeSequenceToValidate[nodeIndex++] = parentNode; parentNode = parentNode.ParentNode; } while (parentNode != null); if (parentNode == null) { //Did not find any type info all the way to the root, currentNode is Document || DocumentFragment nodeIndex = nodeIndex - 1; //Subtract the one for document and set the node to null _nodeSequenceToValidate[nodeIndex] = null; return(GetTypeFromAncestors(elementToValidate, null, nodeIndex)); } else { //Start validating down from the parent or ancestor that has schema info and shallow validate all previous siblings //to correctly ascertain particle for current node CheckNodeSequenceCapacity(nodeIndex); _nodeSequenceToValidate[nodeIndex++] = parentNode; XmlSchemaObject ancestorSchemaObject = parentSchemaInfo.SchemaElement; if (ancestorSchemaObject == null) { ancestorSchemaObject = parentSchemaInfo.SchemaType; } return(GetTypeFromAncestors(elementToValidate, ancestorSchemaObject, nodeIndex)); } }
private XmlAttribute LoadAttributeNode() { XmlReader reader = this.reader; if (reader.IsDefault) { return(this.LoadDefaultAttribute()); } XmlAttribute attribute = this.doc.CreateAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI); IXmlSchemaInfo schemaInfo = reader.SchemaInfo; if (schemaInfo != null) { attribute.XmlName = this.doc.AddAttrXmlName(attribute.Prefix, attribute.LocalName, attribute.NamespaceURI, schemaInfo); } while (reader.ReadAttributeValue()) { XmlNode node; switch (reader.NodeType) { case XmlNodeType.Text: node = this.doc.CreateTextNode(reader.Value); break; case XmlNodeType.EntityReference: node = this.doc.CreateEntityReference(reader.LocalName); if (reader.CanResolveEntity) { reader.ResolveEntity(); this.LoadAttributeValue(node, false); if (node.FirstChild == null) { node.AppendChildForLoad(this.doc.CreateTextNode(string.Empty), this.doc); } } break; default: throw UnexpectedNodeType(reader.NodeType); } attribute.AppendChildForLoad(node, this.doc); } return(attribute); }
// TODO: Check whether this can be removed. //private static bool DeepEqualsWithNormalization(XDocument doc1, XDocument doc2, XmlSchemaSet schemaSet) //{ // XDocument d1 = Normalize(doc1, schemaSet); // XDocument d2 = Normalize(doc2, schemaSet); // return XNode.DeepEquals(d1, d2); //} private static IEnumerable <XAttribute> NormalizeAttributes(XElement element, bool havePsvi) { return(element.Attributes() .Where(a => !a.IsNamespaceDeclaration && (a.Name != Xsi.schemaLocation) && (a.Name != Xsi.noNamespaceSchemaLocation)) .OrderBy(a => a.Name.NamespaceName) .ThenBy(a => a.Name.LocalName) .Select(a => { if (havePsvi) { IXmlSchemaInfo schemaInfo = a.GetSchemaInfo(); XmlSchemaType schemaType = schemaInfo != null ? schemaInfo.SchemaType : null; XmlTypeCode?typeCode = schemaType != null ? schemaType.TypeCode : (XmlTypeCode?)null; switch (typeCode) { case XmlTypeCode.Boolean: return new XAttribute(a.Name, (bool)a); case XmlTypeCode.DateTime: return new XAttribute(a.Name, (DateTime)a); case XmlTypeCode.Decimal: return new XAttribute(a.Name, (decimal)a); case XmlTypeCode.Double: return new XAttribute(a.Name, (double)a); case XmlTypeCode.Float: return new XAttribute(a.Name, (float)a); case XmlTypeCode.HexBinary: case XmlTypeCode.Language: return new XAttribute(a.Name, ((string)a).ToLower()); } } return a; })); }
public void XElementGetSchemaInfo() { string elementName = "body"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // validate element XElement body = xmlDocument.Root.Element(elementName); ExtensionsClass.Validate(body, body.GetSchemaInfo().SchemaElement, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceeded); IXmlSchemaInfo schemaInfo = ExtensionsClass.GetSchemaInfo(body); Assert.NotNull(schemaInfo); }
private XmlAttribute LoadDefaultAttribute() { XmlReader reader = this.reader; XmlAttribute parent = this.doc.CreateDefaultAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI); IXmlSchemaInfo schemaInfo = reader.SchemaInfo; if (schemaInfo != null) { parent.XmlName = this.doc.AddAttrXmlName(parent.Prefix, parent.LocalName, parent.NamespaceURI, schemaInfo); } this.LoadAttributeValue(parent, false); XmlUnspecifiedAttribute attribute2 = parent as XmlUnspecifiedAttribute; if (attribute2 != null) { attribute2.SetSpecified(false); } return(parent); }
public XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = _entries[hashCode & _mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return(e); } } prefix = _nameTable.Add(prefix); localName = _nameTable.Add(localName); ns = _nameTable.Add(ns); int index = hashCode & _mask; XmlName name = XmlName.Create(prefix, localName, ns, hashCode, _ownerDocument, _entries[index], schemaInfo); _entries[index] = name; if (_count++ == _mask) { Grow(); } return(name); }
public XmlName AddName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName e = _entries[hashCode & _mask]; e != null; e = e.next) { if (e.HashCode == hashCode && ((object)e.LocalName == (object)localName || e.LocalName.Equals(localName)) && ((object)e.Prefix == (object)prefix || e.Prefix.Equals(prefix)) && ((object)e.NamespaceURI == (object)ns || e.NamespaceURI.Equals(ns)) && e.Equals(schemaInfo)) { return e; } } prefix = _nameTable.Add(prefix); localName = _nameTable.Add(localName); ns = _nameTable.Add(ns); int index = hashCode & _mask; XmlName name = XmlName.Create(prefix, localName, ns, hashCode, _ownerDocument, _entries[index], schemaInfo); _entries[index] = name; if (_count++ == _mask) { Grow(); } return name; }
public void XAttributeGetSchemaInfo() { string elementName = "note"; string attributeName = "date"; // validate the entire document validationSucceeded = true; ExtensionsClass.Validate(xmlDocument, schemaSet, new ValidationEventHandler(TestValidationHandler), true); Assert.True(validationSucceeded); // validate attribute XAttribute date = xmlDocument.Element(elementName).Attribute(attributeName); ExtensionsClass.Validate(date, date.GetSchemaInfo().SchemaAttribute, schemaSet, new ValidationEventHandler(TestValidationHandler)); Assert.True(validationSucceeded); IXmlSchemaInfo schemaInfo = ExtensionsClass.GetSchemaInfo(date); Assert.NotNull(schemaInfo); }
public XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName name = this.entries[hashCode & this.mask]; name != null; name = name.next) { if ((((name.HashCode == hashCode) && ((name.LocalName == localName) || name.LocalName.Equals(localName))) && ((name.Prefix == prefix) || name.Prefix.Equals(prefix))) && (((name.NamespaceURI == ns) || name.NamespaceURI.Equals(ns)) && name.Equals(schemaInfo))) { return name; } } return null; }
public override XPathSequence Evaluate(XPathSequence iter) { XPathSequence res = Args [0].Evaluate(iter); if (!res.MoveNext()) { return(new XPathEmptySequence(iter.Context)); } XPathNavigator nav = res.Current as XPathNavigator; IXmlSchemaInfo info = nav.NodeType == XPathNodeType.Element ? nav.SchemaInfo : null; if (info != null) { return(new SingleItemIterator(new XPathAtomicValue(info.IsNil, null), iter)); } else { return(new XPathEmptySequence(iter.Context)); } }
private List <string> GetPossibleChilds(XElement xe) { List <string> l = new List <string>(); if (xe != null) { IXmlSchemaInfo ixsi = xe.GetSchemaInfo(); if (ixsi != null) { XmlSchemaType xst = ixsi.SchemaType; if (xst is XmlSchemaComplexType) { this.WalkSchemaParticle(l, ((XmlSchemaComplexType)xst).ContentTypeParticle); } } } return(l); }
public XmlName GetName(string prefix, string localName, string ns, IXmlSchemaInfo schemaInfo) { if (prefix == null) { prefix = string.Empty; } if (ns == null) { ns = string.Empty; } int hashCode = XmlName.GetHashCode(localName); for (XmlName name = this.entries[hashCode & this.mask]; name != null; name = name.next) { if ((((name.HashCode == hashCode) && ((name.LocalName == localName) || name.LocalName.Equals(localName))) && ((name.Prefix == prefix) || name.Prefix.Equals(prefix))) && (((name.NamespaceURI == ns) || name.NamespaceURI.Equals(ns)) && name.Equals(schemaInfo))) { return(name); } } return(null); }
public void SetSchemaInfo(IXmlSchemaInfo schemaInfo) { if (schemaInfo == null) { _edtText.Text = ""; return; } StringBuilder sb = new StringBuilder(); try { if (schemaInfo.SchemaElement != null && schemaInfo.SchemaElement.Annotation != null) { var annElement = (XmlSchemaDocumentation)schemaInfo.SchemaElement.Annotation.Items[0]; append(sb, annElement); } if (schemaInfo.SchemaType != null && schemaInfo.SchemaType.Annotation != null) { var annType = schemaInfo.SchemaType.Annotation.Items[0] as XmlSchemaDocumentation; append(sb, annType); } if (schemaInfo.SchemaAttribute != null && schemaInfo.SchemaAttribute.Annotation != null) { var annAttribute = schemaInfo.SchemaAttribute.Annotation.Items[0] as XmlSchemaDocumentation; append(sb, annAttribute); } } catch (Exception ex) { sb.AppendLine("An error occurred: " + ex.Message); } if (sb.Length == 0) { sb.AppendLine("(No annotation found)"); } _edtText.Text = sb.ToString(); }
static public XPathNavigatorReader Create(XPathNavigator navToRead) { XPathNavigator nav = navToRead.Clone(); IXmlLineInfo xli = nav as IXmlLineInfo; IXmlSchemaInfo xsi = nav as IXmlSchemaInfo; #if NAVREADER_SUPPORTSLINEINFO if (null == xsi) { if (null == xli) { return(new XPathNavigatorReader(nav, xli, xsi)); } else { return(new XPathNavigatorReaderWithLI(nav, xli, xsi)); } } else { if (null == xli) { return(new XPathNavigatorReaderWithSI(nav, xli, xsi)); } else { return(new XPathNavigatorReaderWithLIAndSI(nav, xli, xsi)); } } #else if (null == xsi) { return(new XPathNavigatorReader(nav, xli, xsi)); } else { return(new XPathNavigatorReaderWithSI(nav, xli, xsi)); } #endif }
private void ValidationEventHandler(object sender, ValidationEventArgs e) { IXmlSchemaInfo schema = sender as IXmlSchemaInfo; IXmlLineInfo line = sender as IXmlLineInfo; IXmlNamespaceResolver name = sender as IXmlNamespaceResolver; if (line == null) { return; } // <Error> this._writer.WriteStartElement("Error"); // <Severity></Severity> this._writer.WriteStartElement("Severity"); this._writer.WriteValue(e.Severity.ToString()); this._writer.WriteEndElement(); // <Message></Message> this._writer.WriteStartElement("Message"); this._writer.WriteValue(e.Message); this._writer.WriteEndElement(); // <LineNumber></LineNumber> this._writer.WriteStartElement("LineNumber"); this._writer.WriteValue(line.LineNumber.ToString()); this._writer.WriteEndElement(); // <LinePosition></LinePosition> this._writer.WriteStartElement("LinePosition"); this._writer.WriteValue(line.LinePosition.ToString()); this._writer.WriteEndElement(); // </Error> this._writer.WriteEndElement(); }
// Reads XmlReader and creates Attribute Node. private XmlAttribute ReadAttributeNode (XmlReader reader) { if (reader.NodeType == XmlNodeType.Element) reader.MoveToFirstAttribute (); else if (reader.NodeType != XmlNodeType.Attribute) throw new InvalidOperationException (MakeReaderErrorMessage ("bad position to read attribute.", reader)); XmlAttribute attribute = CreateAttribute (reader.Prefix, reader.LocalName, reader.NamespaceURI); #if NET_2_0 if (reader.SchemaInfo != null) SchemaInfo = reader.SchemaInfo; #endif bool isDefault = reader.IsDefault; ReadAttributeNodeValue (reader, attribute); if (isDefault) attribute.SetDefault (); return attribute; }
XmlNode ReadNodeCore(XmlReader reader) { switch (reader.ReadState) { case ReadState.Interactive: break; case ReadState.Initial: #if NET_2_0 if (reader.SchemaInfo != null) { this.SchemaInfo = new XmlSchemaInfo(reader.SchemaInfo); } #endif reader.Read(); break; default: return(null); } XmlNode n; switch (reader.NodeType) { case XmlNodeType.Attribute: string localName = reader.LocalName; string ns = reader.NamespaceURI; n = ReadAttributeNode(reader); // Keep the current reader position on attribute. reader.MoveToAttribute(localName, ns); return(n); case XmlNodeType.CDATA: n = CreateCDataSection(reader.Value); break; case XmlNodeType.Comment: n = CreateComment(reader.Value); break; case XmlNodeType.Element: XmlElement element = CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.NameTable == this.NameTable); #if NET_2_0 if (reader.SchemaInfo != null) { SchemaInfo = new XmlSchemaInfo(reader.SchemaInfo); } #endif element.IsEmpty = reader.IsEmptyElement; // set the element's attributes. for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); element.SetAttributeNode( ReadAttributeNode(reader)); reader.MoveToElement(); } // FIXME: the code below should be fine and // in some XmlReaders it is much faster, but // caused some breakage in sys.data test. /* * if (reader.MoveToFirstAttribute ()) { * do { * element.SetAttributeNode (ReadAttributeNode (reader)); * } while (reader.MoveToNextAttribute ()); * reader.MoveToElement (); * } */ reader.MoveToElement(); int depth = reader.Depth; if (reader.IsEmptyElement) { n = element; break; } reader.Read(); while (reader.Depth > depth) { n = ReadNodeCore(reader); if (preserveWhitespace || n.NodeType != XmlNodeType.Whitespace) { element.AppendChild(n, false); } } n = element; break; case XmlNodeType.ProcessingInstruction: n = CreateProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.Text: n = CreateTextNode(reader.Value); break; case XmlNodeType.XmlDeclaration: n = CreateXmlDeclaration("1.0", String.Empty, String.Empty); n.Value = reader.Value; break; case XmlNodeType.DocumentType: DTDObjectModel dtd = null; IHasXmlParserContext ctxReader = reader as IHasXmlParserContext; if (ctxReader != null) { dtd = ctxReader.ParserContext.Dtd; } if (dtd != null) { n = CreateDocumentType(dtd); } else { n = CreateDocumentType(reader.Name, reader ["PUBLIC"], reader ["SYSTEM"], reader.Value); } break; case XmlNodeType.EntityReference: if (this.loadMode && this.DocumentType != null && DocumentType.Entities.GetNamedItem(reader.Name) == null) { throw new XmlException("Reference to undeclared entity was found."); } n = CreateEntityReference(reader.Name); // IF argument XmlReader can resolve entity, // ReadNode() also fills children _from it_. // In this case, it is not from doctype node. // (it is kind of sucky design, but it happens // anyways when we modify doctype node). // // It does not happen when !CanResolveEntity. // (In such case AppendChild() will resolve // entity content, as XmlEntityReference does.) if (reader.CanResolveEntity) { reader.ResolveEntity(); reader.Read(); for (XmlNode child; reader.NodeType != XmlNodeType.EndEntity && (child = ReadNode(reader)) != null;) { n.InsertBefore(child, null, false, false); } } break; case XmlNodeType.SignificantWhitespace: n = CreateSignificantWhitespace(reader.Value); break; case XmlNodeType.Whitespace: n = CreateWhitespace(reader.Value); break; case XmlNodeType.None: return(null); default: // No idea why MS does throw NullReferenceException ;-P throw new NullReferenceException("Unexpected node type " + reader.NodeType + "."); } reader.Read(); return(n); }
internal XmlName AddAttrXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo) { XmlName name = this.AddXmlName(prefix, localName, namespaceURI, schemaInfo); if (!this.IsLoading) { object obj2 = name.Prefix; object obj3 = name.NamespaceURI; object obj4 = name.LocalName; if (((obj2 == this.strXmlns) || ((obj2 == this.strEmpty) && (obj4 == this.strXmlns))) ^ (obj3 == this.strReservedXmlns)) { throw new ArgumentException(Res.GetString("Xdom_Attr_Reserved_XmlNS", new object[] { namespaceURI })); } } return name; }
internal XmlName GetXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo) { return this.domNameTable.GetName(prefix, localName, namespaceURI, schemaInfo); }
internal XmlNameEx(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next, IXmlSchemaInfo schemaInfo) : base(prefix, localName, ns, hashCode, ownerDoc, next) { SetValidity(schemaInfo.Validity); SetIsDefault(schemaInfo.IsDefault); SetIsNil(schemaInfo.IsNil); _memberType = schemaInfo.MemberType; _schemaType = schemaInfo.SchemaType; _decl = schemaInfo.SchemaElement != null ? (object)schemaInfo.SchemaElement : (object)schemaInfo.SchemaAttribute; }
public XQuerySequenceType(XmlTypeCode typeCode, IXmlSchemaInfo schemaInfo, Type clrType) { TypeCode = typeCode; NameTest = XmlQualifiedNameTest.Wildcard; Cardinality = XmlTypeCardinality.One; SchemaType = schemaInfo.SchemaType; SchemaElement = schemaInfo.SchemaElement; SchemaAttribute = schemaInfo.SchemaAttribute; ParameterType = clrType; IsNode = TypeCodeIsNodeType(TypeCode); ItemType = TypeCodeToItemType(TypeCode, SchemaType); }
public virtual bool Equals(IXmlSchemaInfo schemaInfo) { return schemaInfo == null; }
public override bool Equals(IXmlSchemaInfo schemaInfo) { if (schemaInfo != null && schemaInfo.Validity == (XmlSchemaValidity)(flags & ValidityMask) && schemaInfo.IsDefault == ((flags & IsDefaultBit) != 0) && schemaInfo.IsNil == ((flags & IsNilBit) != 0) && (object)schemaInfo.MemberType == (object)memberType && (object)schemaInfo.SchemaType == (object)schemaType && (object)schemaInfo.SchemaElement == (object)(decl as XmlSchemaElement) && (object)schemaInfo.SchemaAttribute == (object)(decl as XmlSchemaAttribute)) { return true; } return false; }
XmlNode ReadNodeCore (XmlReader reader) { switch (reader.ReadState) { case ReadState.Interactive: break; case ReadState.Initial: #if NET_2_0 if (reader.SchemaInfo != null) SchemaInfo = reader.SchemaInfo; #endif reader.Read (); break; default: return null; } XmlNode n; switch (reader.NodeType) { case XmlNodeType.Attribute: string localName = reader.LocalName; string ns = reader.NamespaceURI; n = ReadAttributeNode (reader); // Keep the current reader position on attribute. reader.MoveToAttribute (localName, ns); return n; case XmlNodeType.CDATA: n = CreateCDataSection (reader.Value); break; case XmlNodeType.Comment: n = CreateComment (reader.Value); break; case XmlNodeType.Element: XmlElement element = CreateElement (reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.NameTable == this.NameTable); #if NET_2_0 if (reader.SchemaInfo != null) SchemaInfo = reader.SchemaInfo; #endif element.IsEmpty = reader.IsEmptyElement; // set the element's attributes. for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute (i); element.SetAttributeNode ( ReadAttributeNode (reader)); reader.MoveToElement (); } // FIXME: the code below should be fine and // in some XmlReaders it is much faster, but // caused some breakage in sys.data test. /* if (reader.MoveToFirstAttribute ()) { do { element.SetAttributeNode (ReadAttributeNode (reader)); } while (reader.MoveToNextAttribute ()); reader.MoveToElement (); } */ reader.MoveToElement (); int depth = reader.Depth; if (reader.IsEmptyElement) { n = element; break; } reader.Read (); while (reader.Depth > depth) { n = ReadNodeCore (reader); if (preserveWhitespace || n.NodeType != XmlNodeType.Whitespace) element.AppendChild (n, false); } n = element; break; case XmlNodeType.ProcessingInstruction: n = CreateProcessingInstruction (reader.Name, reader.Value); break; case XmlNodeType.Text: n = CreateTextNode (reader.Value); break; case XmlNodeType.XmlDeclaration: n = CreateXmlDeclaration ("1.0" , String.Empty, String.Empty); n.Value = reader.Value; break; case XmlNodeType.DocumentType: DTDObjectModel dtd = null; IHasXmlParserContext ctxReader = reader as IHasXmlParserContext; if (ctxReader != null) dtd = ctxReader.ParserContext.Dtd; if (dtd != null) n = CreateDocumentType (dtd); else n = CreateDocumentType (reader.Name, reader ["PUBLIC"], reader ["SYSTEM"], reader.Value); break; case XmlNodeType.EntityReference: if (this.loadMode && this.DocumentType != null && DocumentType.Entities.GetNamedItem (reader.Name) == null) throw new XmlException ("Reference to undeclared entity was found."); n = CreateEntityReference (reader.Name); // IF argument XmlReader can resolve entity, // ReadNode() also fills children _from it_. // In this case, it is not from doctype node. // (it is kind of sucky design, but it happens // anyways when we modify doctype node). // // It does not happen when !CanResolveEntity. // (In such case AppendChild() will resolve // entity content, as XmlEntityReference does.) if (reader.CanResolveEntity) { reader.ResolveEntity (); reader.Read (); for (XmlNode child; reader.NodeType != XmlNodeType.EndEntity && (child = ReadNode (reader)) != null;) n.InsertBefore (child, null, false, false); } break; case XmlNodeType.SignificantWhitespace: n = CreateSignificantWhitespace (reader.Value); break; case XmlNodeType.Whitespace: n = CreateWhitespace (reader.Value); break; case XmlNodeType.None: return null; default: // No idea why MS does throw NullReferenceException ;-P throw new NullReferenceException ("Unexpected node type " + reader.NodeType + "."); } reader.Read (); return n; }
internal XmlName AddAttrXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo) { XmlName xmlName = AddXmlName(prefix, localName, namespaceURI, schemaInfo); Debug.Assert( (prefix == null) ? (xmlName.Prefix.Length == 0) : (prefix == xmlName.Prefix) ); Debug.Assert( xmlName.LocalName == localName ); Debug.Assert( (namespaceURI == null) ? (xmlName.NamespaceURI.Length == 0) : (xmlName.NamespaceURI == namespaceURI) ); if ( !this.IsLoading ) { // Use atomized versions instead of prefix, localName and nsURI object oPrefix = xmlName.Prefix; object oNamespaceURI = xmlName.NamespaceURI; object oLocalName = xmlName.LocalName; if ( ( oPrefix == (object)strXmlns || ( oPrefix == (object)strEmpty && oLocalName == (object)strXmlns ) ) ^ ( oNamespaceURI == (object)strReservedXmlns ) ) throw new ArgumentException( Res.GetString( Res.Xdom_Attr_Reserved_XmlNS, namespaceURI ) ); } return xmlName; }
internal XPathNavigatorReaderWithSI(XPathNavigator navToRead, IXmlLineInfo xli, IXmlSchemaInfo xsi) : base(navToRead, xli, xsi) { }
public XmlAsyncCheckReaderWithLineInfoNSSchema(XmlReader reader) : base(reader) { _readerAsIXmlSchemaInfo = (IXmlSchemaInfo)reader; }
protected XPathNavigatorReader(XPathNavigator navToRead, IXmlLineInfo xli, IXmlSchemaInfo xsi) { // Need clone that can be moved independently of original navigator _navToRead = navToRead; this.lineInfo = xli; this.schemaInfo = xsi; _nav = XmlEmptyNavigator.Singleton; _state = State.Initial; _depth = 0; _nodeType = XPathNavigatorReader.ToXmlNodeType(_nav.NodeType); }
public override bool Equals(IXmlSchemaInfo schemaInfo) { return ((((schemaInfo != null) && (schemaInfo.Validity == (this.flags & 3))) && ((schemaInfo.IsDefault == ((this.flags & 4) != 0)) && (schemaInfo.IsNil == ((this.flags & 8) != 0)))) && (((schemaInfo.MemberType == this.memberType) && (schemaInfo.SchemaType == this.schemaType)) && ((schemaInfo.SchemaElement == (this.decl as XmlSchemaElement)) && (schemaInfo.SchemaAttribute == (this.decl as XmlSchemaAttribute))))); }
internal XmlName GetXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo) { XmlName n = domNameTable.GetName(prefix, localName, namespaceURI, schemaInfo); Debug.Assert(n == null || ((prefix == null) ? (n.Prefix.Length == 0) : (prefix == n.Prefix))); Debug.Assert(n == null || n.LocalName == localName); Debug.Assert(n == null || ((namespaceURI == null) ? (n.NamespaceURI.Length == 0) : (n.NamespaceURI == namespaceURI))); return n; }
public DmSchemaInfo(IXmlSchemaInfo xmlSchemaInfo) { IsDefault = xmlSchemaInfo.IsDefault; IsNil = xmlSchemaInfo.IsNil; MemberType = xmlSchemaInfo.MemberType; SchemaAttribute = xmlSchemaInfo.SchemaAttribute; SchemaElement = xmlSchemaInfo.SchemaElement; SchemaType = xmlSchemaInfo.SchemaType; Validity = xmlSchemaInfo.Validity; }