示例#1
0
        internal bool Match(DmNode node)
        {
            switch (TypeCode)
            {
                case XmlTypeCode.Item:
                case XmlTypeCode.Node:
                    return true;

                case XmlTypeCode.Document:
                    if (node.NodeType == XPathNodeType.Root)
                    {
                        DmElement documentElement = ((DmRoot)node).DocumentElement;
                        if (documentElement != null)
                        {
                            if (SchemaElement == null)
                            {
                                if (MatchName(documentElement))
                                {
                                    if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic)
                                        return true;
                                    IXmlSchemaInfo schemaInfo = documentElement.SchemaInfo;
                                    if (schemaInfo != null)
                                    {
                                        if (XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty))
                                            return !schemaInfo.IsNil || Nillable;
                                    }
                                    else
                                        return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty);
                                }
                            }
                            else
                            {
                                IXmlSchemaInfo schemaInfo = documentElement.SchemaInfo;
                                if (schemaInfo != null)
                                    return schemaInfo.SchemaElement.QualifiedName == SchemaElement.QualifiedName;
                            }
                        }
                    }
                    break;

                case XmlTypeCode.Element:
                    {
                        if (node.NodeType == XPathNodeType.Element)
                        {
                            if (SchemaElement == null)
                            {
                                if (MatchName(node))
                                {
                                    if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic)
                                        return true;
                                    IXmlSchemaInfo schemaInfo = node.SchemaInfo;
                                    if (schemaInfo != null)
                                    {
                                        if (XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty))
                                            return !schemaInfo.IsNil || Nillable;
                                    }
                                    else
                                        return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty);
                                }
                            }
                            else
                            {
                                IXmlSchemaInfo schemaInfo = node.SchemaInfo;
                                if (schemaInfo != null)
                                    return schemaInfo.SchemaElement.QualifiedName == SchemaElement.QualifiedName;
                            }
                        }
                    }
                    break;

                case XmlTypeCode.Attribute:
                    {
                        if (node.NodeType == XPathNodeType.Attribute)
                        {
                            if (SchemaAttribute == null)
                            {
                                if (MatchName(node))
                                {
                                    if (SchemaType == null || SchemaType == XmlSchema.UntypedAtomic)
                                        return true;
                                    IXmlSchemaInfo schemaInfo = node.SchemaInfo;
                                    if (schemaInfo == null)
                                        return XmlSchemaType.IsDerivedFrom(XmlSchema.UntypedAtomic, SchemaType, XmlSchemaDerivationMethod.Empty);
                                    else
                                        return XmlSchemaType.IsDerivedFrom(schemaInfo.SchemaType, SchemaType, XmlSchemaDerivationMethod.Empty);
                                }
                            }
                            else
                            {
                                IXmlSchemaInfo schemaInfo = node.SchemaInfo;
                                if (schemaInfo != null)
                                    return schemaInfo.SchemaAttribute.QualifiedName == SchemaAttribute.QualifiedName;
                            }
                        }
                    }
                    break;

                case XmlTypeCode.ProcessingInstruction:
                    return (node.NodeType == XPathNodeType.ProcessingInstruction &&
                         (NameTest.IsNameWildcard || NameTest.Name == node.Name));

                case XmlTypeCode.Comment:
                    return node.NodeType == XPathNodeType.Comment;

                case XmlTypeCode.Text:
                    return node.NodeType == XPathNodeType.Text ||
                       node.NodeType == XPathNodeType.SignificantWhitespace;
            }
            return false;
        }
示例#2
0
        private void GetNodesVisitor(XQueryExprBase[] path, DmNode curr, int index, int length, List<DmNode> res)
        {
            XQueryStepExpr expr = path[index] as XQueryStepExpr;
            if (expr == null)
                throw new ArgumentException();
            DmNode[] nodes;
            switch (expr.ExprType)
            {
                case XQueryPathExprType.Self:
                    nodes = curr.GetSelf();
                    break;

                case XQueryPathExprType.Child:
                    nodes = curr.GetChilds();
                    break;

                case XQueryPathExprType.Descendant:
                    nodes = curr.GetDescendants();
                    break;

                case XQueryPathExprType.DescendantOrSelf:
                    nodes = curr.GetDescendantOrSelf();
                    break;

                default:
                    throw new ArgumentException();
            }
            foreach (DmNode node in nodes)
                if (node.TestNode(expr.NameTest, expr.TypeTest))
                {
                    if (index < length -1)
                        GetNodesVisitor(path, node, index + 1, length, res);
                    else
                        res.Add(node);
                }
        }
示例#3
0
 private bool MatchName(DmNode node)
 {
     return (NameTest.IsNamespaceWildcard || NameTest.Namespace == node.NamespaceURI) &&
        (NameTest.IsNameWildcard || NameTest.Name == node.LocalName);
 }
示例#4
0
 private void DescendantsVisitor(List<DmNode> nodes, bool recursive, DmNode exclude)
 {
     if (ChildNodes != null)
         foreach (DmNode node in ChildNodes)
         {
             if (node != exclude)
                 nodes.Add(node);
             if (recursive)
                 node.DescendantsVisitor(nodes, true, exclude);
         }
     DmContainer container = this as DmContainer;
     if (container != null)
     {
         if (container.ChildText != null)
             nodes.Add(container.ChildText);
         if (container.ChildComment != null)
             nodes.Add(container.ChildComment);
         if (container.ChildWhitespace != null)
             nodes.Add(container.ChildWhitespace);
     }
 }
示例#5
0
 public bool IsAncestor(DmNode node)
 {
     for (node = node.ParentNode; node != null; node = node.ParentNode)
     {
         if (node == this)
             return true;
     }
     return false;
 }
示例#6
0
 public DmWhitespace(DmNode parent)
 {
     _parent = parent;
 }
示例#7
0
 public DmText(DmNode parent)
 {
     _parent = parent;
 }
示例#8
0
 public DmComment(DmNode parent)
 {
     _parent = parent;
 }