Пример #1
0
        public Processor.OutputResult RecordDone(RecordBuilder record) {
            Debug.Assert(record != null);

            BuilderInfo mainNode = record.MainNode;
            documentIndex++;
            mainNode.LocalName  = doc.nt.Add(mainNode.LocalName);
            mainNode.NamespaceURI   = doc.nt.Add(mainNode.NamespaceURI);
            switch(mainNode.NodeType) {
                case XmlNodeType.Element: {                    
                    XPathElement e = mainNode.IsEmptyTag ? 
                        new XPathEmptyElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI, 0, 0, node.topNamespace, documentIndex) :
                        new XPathElement(     mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI, 0, 0, node.topNamespace, documentIndex)
                    ;
                    node.AppendChild( e );

                    XPathNamespace last = null;
                    for (int attrib = 0; attrib < record.AttributeCount; attrib ++) {
                        documentIndex++;
                        Debug.Assert(record.AttributeList[attrib] is BuilderInfo);
                        BuilderInfo attrInfo = (BuilderInfo) record.AttributeList[attrib];
                        if (attrInfo.NamespaceURI == Keywords.s_XmlnsNamespace) {
                            XPathNamespace tmp = new XPathNamespace(attrInfo.Prefix == string.Empty ? string.Empty : attrInfo.LocalName, attrInfo.Value, documentIndex);
                            tmp.next = last;
                            last = tmp;
                        }
                        else {
                            e.AppendAttribute( new XPathAttribute( attrInfo.Prefix, attrInfo.LocalName, attrInfo.NamespaceURI, attrInfo.Value, documentIndex ) );
                        }
                    }

                    if (last != null) {
                        e.AppendNamespaces(last);
                    }

                    if (!mainNode.IsEmptyTag) {
                        node = e;
                    }
                    break;
                }

                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    node.AppendChild( new XPathText( mainNode.Value, 0, 0, documentIndex ) );
                    break;

                case XmlNodeType.ProcessingInstruction:
                    node.AppendChild( new XPathProcessingInstruction( mainNode.LocalName, mainNode.Value, documentIndex ) );
                    break;

                case XmlNodeType.Comment:
                    node.AppendChild( new XPathComment( mainNode.Value, documentIndex ) );
                    break;

                case XmlNodeType.Document:
                    break;

                case XmlNodeType.EndElement:
                    node = node.parent;
                    break;

                default:
                    Debug.Fail("Invalid NodeType on output: " + mainNode.NodeType.ToString());
                    break;
            }

            record.Reset();
            return Processor.OutputResult.Continue;
        }
Пример #2
0
	    private void ReadChildNodes( XPathContainer parent, string parentBaseUri, XmlReader reader, PositionInfo positionInfo ) {
		    do {
		        documentIndex++;
			    switch( reader.NodeType ) {
				case XmlNodeType.Element: {
                    string baseUri = reader.BaseURI;
                    XPathElement e = null;
                    if( reader.IsEmptyElement ) {
                        e = new XPathEmptyElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
    					ReadAttributes( e, reader );
                    }
                    else {
                        e = new XPathElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, positionInfo.LineNumber, positionInfo.LinePosition, parent.topNamespace, documentIndex );
    					ReadAttributes( e, reader );
    					reader.Read();
	    				ReadChildNodes( e, baseUri, reader, positionInfo );
                    }
                    if (parentBaseUri != baseUri) {
                        // We can't user Ref.Equial Because Reader fails to fully atomize base Uri.
                        if (elementBaseUriMap == null) {
                            elementBaseUriMap = new Hashtable();
                        }
                        elementBaseUriMap[e] = baseUri;
                    }
                    parent.AppendChild( e );
                    break;
				}	

				case XmlNodeType.Comment:
                    parent.AppendChild( new XPathComment( reader.Value, documentIndex ) );
                    break;

				case XmlNodeType.ProcessingInstruction:
                    parent.AppendChild( new XPathProcessingInstruction( reader.LocalName, reader.Value, documentIndex ) );
                    break;

				case XmlNodeType.SignificantWhitespace:
                    if( reader.XmlSpace == XmlSpace.Preserve ) {
                        parent.AppendSignificantWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    }
                    else {
                        // SWS without xml:space='preserve' is not really significant for XPath.
                        // so we treat it as just WS
                        goto case XmlNodeType.Whitespace;
                    }
                    break;

				case XmlNodeType.Whitespace:
                    if( space == XmlSpace.Preserve ) {
                        parent.AppendWhitespace( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    }
                    break;

				case XmlNodeType.CDATA:
				case XmlNodeType.Text:
                    parent.AppendText( reader.Value, positionInfo.LineNumber, positionInfo.LinePosition, documentIndex );
                    break;

                case XmlNodeType.EntityReference:
                    reader.ResolveEntity();
                    reader.Read();
                    ReadChildNodes( parent, parentBaseUri, reader, positionInfo);
                    break;

                case XmlNodeType.EndEntity:
				case XmlNodeType.EndElement:
                case XmlNodeType.None:
					return;

                case XmlNodeType.DocumentType:
                    XmlValidatingReader vr = reader as XmlValidatingReader;
                    if ( vr != null ) {
                        SchemaInfo info = vr.GetSchemaInfo();
                        if ( info != null ) {
                            GetIDInfo( info);
                        }
                    }
                    break;
                case XmlNodeType.XmlDeclaration:
                default:
                    break;
			    }
		    }while( reader.Read() );
	    }
Пример #3
0
 internal NavigatorOutput() {
     doc = new XPathDocument();
     node = doc.root;
 }