public XmlQualifiedNameTest Intersect(XmlQualifiedNameTest other) { // Namespace // this\other ~y * y // ~x x=y ? this|other : null this x!=y ? other : null // * other this|other other // x x!=y ? this : null this x=y ? this|other : null XmlQualifiedNameTest namespaceFrom = IsNamespaceSubsetOf(other) ? this : other.IsNamespaceSubsetOf(this) ? other : null; XmlQualifiedNameTest nameFrom = IsNameSubsetOf(other) ? this : other.IsNameSubsetOf(this) ? other : null; if ((object)namespaceFrom == (object)nameFrom) { return(namespaceFrom); } else if (namespaceFrom == null || nameFrom == null) { return(null); } else { return(new XmlQualifiedNameTest(nameFrom.Name, namespaceFrom.Namespace, namespaceFrom.ExcludeNamespace)); } }
/// <summary> /// True if this matches every QName other does /// </summary> public bool IsSubsetOf(XmlQualifiedNameTest other) { return IsNameSubsetOf(other) && IsNamespaceSubsetOf(other); }
// private bool IsNamespaceSubsetOf(XmlQualifiedNameTest other) { return other.IsNamespaceWildcard || (this.exclude == other.exclude && this.Namespace == other.Namespace) || (other.exclude && !this.exclude && this.Namespace != other.Namespace); }
private bool IsNameSubsetOf(XmlQualifiedNameTest other) { return other.IsNameWildcard || this.Name == other.Name; }
/// <summary> /// Return the result of intersection with other /// </summary> public XmlQualifiedNameTest Intersect(XmlQualifiedNameTest other) { // Namespace // this\other ~y * y // ~x x=y ? this|other : null this x!=y ? other : null // * other this|other other // x x!=y ? this : null this x=y ? this|other : null XmlQualifiedNameTest namespaceFrom = IsNamespaceSubsetOf(other) ? this : other.IsNamespaceSubsetOf(this) ? other : null; XmlQualifiedNameTest nameFrom = IsNameSubsetOf(other) ? this : other.IsNameSubsetOf(this) ? other : null; if ((object)namespaceFrom == (object)nameFrom) { return namespaceFrom; } else if (namespaceFrom == null || nameFrom == null) { return null; } else { return new XmlQualifiedNameTest(nameFrom.Name, namespaceFrom.Namespace, namespaceFrom.ExcludeNamespace); } }
/// <summary> /// Return true if the result of intersection with other is not empty /// </summary> public bool HasIntersection(XmlQualifiedNameTest other) { return (IsNamespaceSubsetOf(other) || other.IsNamespaceSubsetOf(this)) && (IsNameSubsetOf(other) || other.IsNameSubsetOf(this)); }
/// <summary> /// Private constructor. Create methods should be used to create instances. /// </summary> private ItemType(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType schemaType, bool isNillable, bool isStrict, bool isNotRtf) { Debug.Assert(nameTest != null, "nameTest cannot be null"); Debug.Assert(schemaType != null, "schemaType cannot be null"); this.code = code; this.nameTest = nameTest; this.schemaType = schemaType; this.isNillable = isNillable; this.isStrict = isStrict; this.isNotRtf = isNotRtf; Debug.Assert(!IsAtomicValue || schemaType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic); switch (code) { case XmlTypeCode.Item: this.nodeKinds = XmlNodeKindFlags.Any; break; case XmlTypeCode.Node: this.nodeKinds = XmlNodeKindFlags.Any; break; case XmlTypeCode.Document: this.nodeKinds = XmlNodeKindFlags.Document; break; case XmlTypeCode.Element: this.nodeKinds = XmlNodeKindFlags.Element; break; case XmlTypeCode.Attribute: this.nodeKinds = XmlNodeKindFlags.Attribute; break; case XmlTypeCode.Namespace: this.nodeKinds = XmlNodeKindFlags.Namespace; break; case XmlTypeCode.ProcessingInstruction: this.nodeKinds = XmlNodeKindFlags.PI; break; case XmlTypeCode.Comment: this.nodeKinds = XmlNodeKindFlags.Comment; break; case XmlTypeCode.Text: this.nodeKinds = XmlNodeKindFlags.Text; break; default: this.nodeKinds = XmlNodeKindFlags.None; break; } }
/// <summary> /// Create Document, Element or Attribute with specified name test, content type and nillable. /// </summary> public static XmlQueryType Create(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable) { // If this is a Document, Element, or Attribute, switch (code) { case XmlTypeCode.Document: case XmlTypeCode.Element: if (nameTest.IsWildcard) { // Normalize document(*, xs:anyType), element(*, xs:anyType) if (contentType == XmlSchemaComplexType.AnyType) return Create(code, false); // Normalize document(xs:untypedAny), element(*, xs:untypedAny) if (contentType == XmlSchemaComplexType.UntypedAnyType) { Debug.Assert(!isNillable); if (code == XmlTypeCode.Element) return UntypedElement; if (code == XmlTypeCode.Document) return UntypedDocument; } } // Create new ItemType return new ItemType(code, nameTest, contentType, isNillable, false, true); case XmlTypeCode.Attribute: if (nameTest.IsWildcard) { // Normalize attribute(xs:anySimpleType) if (contentType == DatatypeImplementation.AnySimpleType) return Create(code, false); // Normalize attribute(xs:untypedAtomic) if (contentType == DatatypeImplementation.UntypedAtomicType) return UntypedAttribute; } // Create new ItemType return new ItemType(code, nameTest, contentType, isNillable, false, true); default: return Create(code, false); } }
/// <summary> /// Create an XmlQueryType having an XSD name test, content type, nillable and cardinality. /// </summary> /// <param name="code">unless code is Document, Element, or Attribute, "contentType" is ignored</param> /// <param name="nameTest">name test on the node</param> /// <param name="contentType">content type of the node</param> /// <param name="isNillable">nillable property</param> /// <param name="card">cardinality</param> /// <returns>the item type</returns> public XmlQueryType Type(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable, XmlQueryCardinality card) { return SequenceType.Create(ItemType.Create(code, nameTest, contentType, isNillable), card); }
/// <summary> /// Create an XmlQueryType having an XSD name test, content type and nillable. /// </summary> /// <param name="code">unless code is Document, Element, or Attribute, "contentType" is ignored</param> /// <param name="nameTest">name test on the node</param> /// <param name="contentType">content type of the node</param> /// <param name="isNillable">nillable property</param> /// <returns>the item type</returns> public XmlQueryType Type(XmlTypeCode code, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable) { return ItemType.Create(code, nameTest, contentType, isNillable); }
/// <summary> /// Create a Node XmlQueryType having an XSD content type. /// </summary> /// <param name="code">unless kind is Root, Element, or Attribute, "contentType" is ignored</param> /// <param name="contentType">content type of the node</param> /// <returns>the node type</returns> public static XmlQueryType Type(XPathNodeType kind, XmlQualifiedNameTest nameTest, XmlSchemaType contentType, bool isNillable) { return ItemType.Create(NodeKindToTypeCode[(int)kind], nameTest, contentType, isNillable); }
private bool IsNamespaceSubsetOf(XmlQualifiedNameTest other) { return(other.IsNamespaceWildcard || (this.exclude == other.exclude && this.Namespace == other.Namespace) || (other.exclude && !this.exclude && this.Namespace != other.Namespace)); }
private bool IsNameSubsetOf(XmlQualifiedNameTest other) { return(other.IsNameWildcard || this.Name == other.Name); }
/// <summary> /// Return true if the result of intersection with other is not empty /// </summary> public bool HasIntersection(XmlQualifiedNameTest other) { return((IsNamespaceSubsetOf(other) || other.IsNamespaceSubsetOf(this)) && (IsNameSubsetOf(other) || other.IsNameSubsetOf(this))); }
/// <summary> /// True if this matches every QName other does /// </summary> public bool IsSubsetOf(XmlQualifiedNameTest other) { return(IsNameSubsetOf(other) && IsNamespaceSubsetOf(other)); }