internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.DisableOutputEscaping))
            {
                this.disableOutputEscaping = compiler.GetYesNo(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Terminate))
            {
                _Terminate = compiler.GetYesNo(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Select))
            {
                this.selectKey = compiler.AddQuery(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Name))
            {
                _nameAvt = Avt.CompileAvt(compiler, value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        internal void CompileNamespaceAlias(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;
            string         element = input.LocalName;
            string?        namespace1 = null, namespace2 = null;
            string?        prefix1 = null, prefix2 = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

                    if (nspace.Length != 0)
                    {
                        continue;
                    }

                    if (Ref.Equal(name, input.Atoms.StylesheetPrefix))
                    {
                        prefix1    = input.Value;
                        namespace1 = compiler.GetNsAlias(ref prefix1);
                    }
                    else if (Ref.Equal(name, input.Atoms.ResultPrefix))
                    {
                        prefix2    = input.Value;
                        namespace2 = compiler.GetNsAlias(ref prefix2);
                    }
                    else
                    {
                        if (!compiler.ForwardCompatibility)
                        {
                            throw XsltException.Create(SR.Xslt_InvalidAttribute, name, element);
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            CheckRequiredAttribute(compiler, namespace1, "stylesheet-prefix");
            CheckRequiredAttribute(compiler, namespace2, "result-prefix");
            CheckEmpty(compiler);

            //String[] resultarray = { prefix2, namespace2 };
            compiler.AddNamespaceAlias(namespace1 !, new NamespaceInfo(prefix2, namespace2, compiler.Stylesheetid));
        }
Example #6
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Name))
            {
                Debug.Assert(_name == null);
                _name = compiler.CreateXPathQName(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        internal void CompileSelectiveTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            do
            {
                if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl) &&
                    Ref.Equal(input.LocalName, input.Atoms.Fallback))
                {
                    fallback = true;
                    if (compiler.Recurse())
                    {
                        CompileTemplate(compiler);
                        compiler.ToParent();
                    }
                }
            }while (compiler.Advance());
        }
Example #8
0
        internal bool FindPrefix(string urn, out string prefix)
        {
            Debug.Assert(urn != null);

            for (NamespaceDecl?scope = this.scopes; scope != null; scope = scope.Next)
            {
                if (Ref.Equal(scope.Uri, urn) &&
                    scope.Prefix != null &&
                    scope.Prefix.Length > 0)
                {
                    prefix = scope.Prefix;
                    return(true);
                }
            }

            prefix = string.Empty;
            return(false);
        }
Example #9
0
        // nav1 and nav2 are assumed to belong to the same document
        public bool IsSameNodeSort(XPathNavigator nav1, XPathNavigator nav2)
        {
            Debug.Assert(XPathNodeType.SignificantWhitespace == XPathNodeType.Text + 1);
            Debug.Assert(XPathNodeType.Whitespace == XPathNodeType.Text + 2);

            XPathNodeType nt1 = nav1.NodeType;
            XPathNodeType nt2 = nav2.NodeType;

            // If one of nodes is a text node, the other one must also be a text node
            if (XPathNodeType.Text <= nt1 && nt1 <= XPathNodeType.Whitespace)
            {
                return(XPathNodeType.Text <= nt2 && nt2 <= XPathNodeType.Whitespace);
            }

            // Otherwise nodes must have the same node kind, the same local name, and the same namespace URI
            Debug.Assert((object)nav1.NameTable == (object)nav2.NameTable, "Ref.Equal cannot be used if navigators have different name tables");
            return(nt1 == nt2 && Ref.Equal(nav1.LocalName, nav2.LocalName) && Ref.Equal(nav1.NamespaceURI, nav2.NamespaceURI));
        }
Example #10
0
        private void FixupAttributes(int attributeCount)
        {
            for (int attr = 0; attr < attributeCount; attr++)
            {
                Debug.Assert(_attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_attributeList[attr] !;


                if (Ref.Equal(info.NamespaceURI, _atoms.Empty))
                {
                    info.Prefix = _atoms.Empty;
                }
                else
                {
                    if (Ref.Equal(info.Prefix, _atoms.Empty))
                    {
                        info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                    }
                    else
                    {
                        bool   thisScope = false;
                        string?nspace    = _scopeManager.ResolveNamespace(info.Prefix, out thisScope);
                        if (nspace != null)
                        {
                            if (!Ref.Equal(info.NamespaceURI, nspace))
                            {
                                if (thisScope)
                                { // prefix conflict
                                    info.Prefix = GetPrefixForNamespace(info.NamespaceURI);
                                }
                                else
                                {
                                    DeclareNamespace(info.NamespaceURI, info.Prefix);
                                }
                            }
                        }
                        else
                        {
                            DeclareNamespace(info.NamespaceURI, info.Prefix);
                        }
                    }
                }
            }
        }
Example #11
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Match))
            {
                Debug.Assert(_matchKey == Compiler.InvalidQueryKey);
                _matchKey = compiler.AddQuery(value, /*allowVars:*/ false, /*allowKey:*/ true, /*pattern*/ true);
            }
            else if (Ref.Equal(name, compiler.Atoms.Name))
            {
                Debug.Assert(_name == null);
                _name = compiler.CreateXPathQName(value);
            }
            else if (Ref.Equal(name, compiler.Atoms.Priority))
            {
                Debug.Assert(double.IsNaN(_priority));
                _priority = XmlConvert.ToXPathDouble(value);
                if (double.IsNaN(_priority) && !compiler.ForwardCompatibility)
                {
                    throw XsltException.Create(SR.Xslt_InvalidAttrValue, "priority", value);
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.Mode))
            {
                Debug.Assert(_mode == null);
                if (compiler.AllowBuiltInMode && value == "*")
                {
                    _mode = Compiler.BuiltInMode;
                }
                else
                {
                    _mode = compiler.CreateXPathQName(value);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #12
0
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (compiler.Recurse())
            {
                do
                {
                    switch (input.NodeType)
                    {
                    case XPathNodeType.Element:
                        compiler.PushNamespaceScope();
                        string nspace = input.NamespaceURI;
                        string name   = input.LocalName;

                        if (Ref.Equal(nspace, input.Atoms.UriXsl) && Ref.Equal(name, input.Atoms.WithParam))
                        {
                            WithParamAction par = compiler.CreateWithParamAction();
                            CheckDuplicateParams(par.Name);
                            AddAction(par);
                        }
                        else
                        {
                            throw compiler.UnexpectedKeyword();
                        }
                        compiler.PopScope();
                        break;

                    case XPathNodeType.Comment:
                    case XPathNodeType.ProcessingInstruction:
                    case XPathNodeType.Whitespace:
                    case XPathNodeType.SignificantWhitespace:
                        break;

                    default:
                        throw XsltException.Create(SR.Xslt_InvalidContents, "call-template");
                    }
                } while (compiler.Advance());

                compiler.ToParent();
            }
        }
Example #13
0
        // SxS: This method processes resource names read from the source document and does not expose
        // any resources to the caller. It is fine to suppress the SxS warning.
        private SchemaElementDecl?ThoroughGetElementDecl()
        {
            if (reader.Depth == 0)
            {
                LoadSchema(string.Empty);
            }
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    string objectNs   = reader.NamespaceURI;
                    string objectName = reader.LocalName;
                    if (Ref.Equal(objectNs, SchemaNames.NsXmlNs))
                    {
                        LoadSchema(reader.Value);
                        if (_isProcessContents)
                        {
                            _nsManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
                        }
                    }
                    if (
                        Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) &&
                        Ref.Equal(objectName, SchemaNames.QnDtDt.Name)
                        )
                    {
                        reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
                    }
                } while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }

            SchemaElementDecl?elementDecl = schemaInfo !.GetElementDecl(elementName);

            if (elementDecl == null)
            {
                if (schemaInfo.TargetNamespaces.ContainsKey(context !.Namespace !))
                {
                    SendValidationEvent(SR.Sch_UndeclaredElement, XmlSchemaValidator.QNameString(context.LocalName !, context.Namespace !));
                }
            }
            return(elementDecl);
        }
Example #14
0
        private void CompileContent(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            if (compiler.Recurse())
            {
                do
                {
                    switch (input.NodeType)
                    {
                    case XPathNodeType.Element:
                        compiler.PushNamespaceScope();

                        string nspace = input.NamespaceURI;
                        string name   = input.LocalName;

                        if (Ref.Equal(nspace, input.Atoms.UriXsl) && Ref.Equal(name, input.Atoms.Attribute))
                        {
                            // found attribute so add it
                            AddAction(compiler.CreateAttributeAction());
                        }
                        else
                        {
                            throw compiler.UnexpectedKeyword();
                        }
                        compiler.PopScope();
                        break;

                    case XPathNodeType.Comment:
                    case XPathNodeType.ProcessingInstruction:
                    case XPathNodeType.Whitespace:
                    case XPathNodeType.SignificantWhitespace:
                        break;

                    default:
                        throw XsltException.Create(SR.Xslt_InvalidContents, "attribute-set");
                    }
                }while (compiler.Advance());

                compiler.ToParent();
            }
        }
Example #15
0
        private void BeginNamespace(string name, string nspace)
        {
            bool thisScope = false;

            if (Ref.Equal(name, _atoms.Empty))
            {
                if (Ref.Equal(nspace, _scopeManager.DefaultNamespace))
                {
                    // Main Node is OK
                }
                else if (Ref.Equal(_mainNode.NamespaceURI, _atoms.Empty))
                {
                    // http://www.w3.org/1999/11/REC-xslt-19991116-errata/ E25
                    // Should throw an error but ingnoring it in Everett.
                    // Would be a breaking change
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            else
            {
                string?nspaceDeclared = _scopeManager.ResolveNamespace(name, out thisScope);
                if (nspaceDeclared != null)
                {
                    if (!Ref.Equal(nspace, nspaceDeclared))
                    {
                        if (!thisScope)
                        {
                            DeclareNamespace(nspace, name);
                        }
                    }
                }
                else
                {
                    DeclareNamespace(nspace, name);
                }
            }
            _currentInfo          = _dummy;
            _currentInfo.NodeType = XmlNodeType.Attribute;
        }
Example #16
0
 public string GetNsAlias(ref string prefix)
 {
     Debug.Assert(
         Ref.Equal(_input.LocalName, _input.Atoms.StylesheetPrefix) ||
         Ref.Equal(_input.LocalName, _input.Atoms.ResultPrefix)
         );
     if (prefix == "#default")
     {
         prefix = string.Empty;
         return(this.DefaultNamespace);
     }
     else
     {
         if (!PrefixQName.ValidatePrefix(prefix))
         {
             throw XsltException.Create(SR.Xslt_InvalidAttrValue, _input.LocalName, prefix);
         }
         return(this.ResolveXPathNamespace(prefix));
     }
 }
Example #17
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Test))
            {
                if (_type == ConditionType.ConditionOtherwise)
                {
                    return(false);
                }
                _testKey = compiler.AddBooleanQuery(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #18
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Select))
            {
                _selectKey = compiler.AddQuery(value);
            }
            else if (Ref.Equal(name, compiler.Atoms.Mode))
            {
                Debug.Assert(_mode == null);
                _mode = compiler.CreateXPathQName(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #19
0
        /*
         * CompileTopLevelElements
         */
        protected void CompileDocument(Compiler compiler, bool inInclude)
        {
            NavigatorInput input = compiler.Input;

            // SkipToElement :
            while (input.NodeType != XPathNodeType.Element)
            {
                if (!compiler.Advance())
                {
                    throw XsltException.Create(SR.Xslt_WrongStylesheetElement);
                }
            }

            Debug.Assert(compiler.Input.NodeType == XPathNodeType.Element);
            if (Ref.Equal(input.NamespaceURI, input.Atoms.UriXsl))
            {
                if (
                    !Ref.Equal(input.LocalName, input.Atoms.Stylesheet) &&
                    !Ref.Equal(input.LocalName, input.Atoms.Transform)
                    )
                {
                    throw XsltException.Create(SR.Xslt_WrongStylesheetElement);
                }
                compiler.PushNamespaceScope();
                CompileStylesheetAttributes(compiler);
                CompileTopLevelElements(compiler);
                if (!inInclude)
                {
                    CompileImports(compiler);
                }
            }
            else
            {
                // single template
                compiler.PushLiteralScope();
                CompileSingleTemplate(compiler);
            }

            compiler.PopScope();
        }
Example #20
0
        internal static string XdrCanonizeUri(string uri, XmlNameTable nameTable, SchemaNames schemaNames)
        {
            string canonicalUri;
            int    offset  = 5;
            bool   convert = false;

            if (uri.Length > 5 && uri.StartsWith("uuid:", StringComparison.Ordinal))
            {
                convert = true;
            }
            else if (uri.Length > 9 && uri.StartsWith("urn:uuid:", StringComparison.Ordinal))
            {
                convert = true;
                offset  = 9;
            }

            if (convert)
            {
                canonicalUri = nameTable.Add(string.Concat(uri.AsSpan(0, offset), CultureInfo.InvariantCulture.TextInfo.ToUpper(uri.Substring(offset, uri.Length - offset))));
            }
            else
            {
                canonicalUri = uri;
            }

            if (
                Ref.Equal(schemaNames.NsDataTypeAlias, canonicalUri) ||
                Ref.Equal(schemaNames.NsDataTypeOld, canonicalUri)
                )
            {
                canonicalUri = schemaNames.NsDataType;
            }
            else if (Ref.Equal(schemaNames.NsXdrAlias, canonicalUri))
            {
                canonicalUri = schemaNames.NsXdr;
            }

            return(canonicalUri);
        }
Example #21
0
        internal string GetSingleAttribute(string attributeAtom)
        {
            NavigatorInput input   = Input;
            string         element = input.LocalName;
            string         value   = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

                    if (nspace.Length != 0)
                    {
                        continue;
                    }

                    if (Ref.Equal(name, attributeAtom))
                    {
                        value = input.Value;
                    }
                    else
                    {
                        if (!this.ForwardCompatibility)
                        {
                            throw XsltException.Create(SR.Xslt_InvalidAttribute, name, element);
                        }
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            if (value == null)
            {
                throw XsltException.Create(SR.Xslt_MissingAttribute, attributeAtom);
            }
            return(value);
        }
Example #22
0
        internal void CompileSingleTemplate(Compiler compiler)
        {
            NavigatorInput input = compiler.Input;

            //
            // find mandatory version attribute and launch compilation of single template
            //

            string?version = null;

            if (input.MoveToFirstAttribute())
            {
                do
                {
                    string nspace = input.NamespaceURI;
                    string name   = input.LocalName;

                    if (Ref.Equal(nspace, input.Atoms.UriXsl) &&
                        Ref.Equal(name, input.Atoms.Version))
                    {
                        version = input.Value;
                    }
                }while (input.MoveToNextAttribute());
                input.ToParent();
            }

            if (version == null)
            {
                if (Ref.Equal(input.LocalName, input.Atoms.Stylesheet) &&
                    input.NamespaceURI == XmlReservedNs.NsWdXsl)
                {
                    throw XsltException.Create(SR.Xslt_WdXslNamespace);
                }
                throw XsltException.Create(SR.Xslt_WrongStylesheetElement);
            }

            compiler.AddTemplate(compiler.CreateSingleTemplateAction());
        }
Example #23
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Name))
            {
                Debug.Assert(this.name == null);
                this.name = compiler.CreateXPathQName(value);
            }
            else if (Ref.Equal(name, compiler.Atoms.UseAttributeSets))
            {
                // create a UseAttributeSetsAction
                // sets come before xsl:attributes
                AddAction(compiler.CreateUseAttributeSetsAction());
            }
            else
            {
                return(false);
            }

            return(true);
        }
        internal override void Compile(Compiler compiler)
        {
            Debug.Assert(Ref.Equal(compiler.Input.LocalName, compiler.Atoms.UseAttributeSets));
            _useString = compiler.Input.Value;

            Debug.Assert(_useAttributeSets == null);

            if (_useString.Length == 0)
            {
                // Split creates empty node is spliting empty string
                _useAttributeSets = Array.Empty <XmlQualifiedName>();
                return;
            }

            string[] qnames = XmlConvert.SplitString(_useString);

            try
            {
                _useAttributeSets = new XmlQualifiedName[qnames.Length];
                {
                    for (int i = 0; i < qnames.Length; i++)
                    {
                        _useAttributeSets[i] = compiler.CreateXPathQName(qnames[i]);
                    }
                }
            }
            catch (XsltException)
            {
                if (!compiler.ForwardCompatibility)
                {
                    // Rethrow the exception if we're not in forwards-compatible mode
                    throw;
                }
                // Ignore the whole list in forwards-compatible mode
                _useAttributeSets = Array.Empty <XmlQualifiedName>();
            }
        }
Example #25
0
        internal override bool CompileAttribute(Compiler compiler)
        {
            string name  = compiler.Input.LocalName;
            string value = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Name))
            {
                _nameAvt = Avt.CompileAvt(compiler, value);
            }
            else if (Ref.Equal(name, compiler.Atoms.Namespace))
            {
                _nsAvt = Avt.CompileAvt(compiler, value);
            }
            else if (Ref.Equal(name, compiler.Atoms.UseAttributeSets))
            {
                AddAction(compiler.CreateUseAttributeSetsAction());
            }
            else
            {
                return(false);
            }

            return(true);
        }
Example #26
0
        private void AnalyzeSpaceLang()
        {
            Debug.Assert(_mainNode.NodeType == XmlNodeType.Element);

            for (int attr = 0; attr < _attributeCount; attr++)
            {
                Debug.Assert(_attributeList[attr] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_attributeList[attr] !;

                if (Ref.Equal(info.Prefix, _atoms.Xml))
                {
                    OutputScope scope = _scopeManager.CurrentElementScope;

                    if (Ref.Equal(info.LocalName, _atoms.Lang))
                    {
                        scope.Lang = info.Value;
                    }
                    else if (Ref.Equal(info.LocalName, _atoms.Space))
                    {
                        scope.Space = TranslateXmlSpace(info.Value);
                    }
                }
            }
        }
Example #27
0
        internal string ResolveNamespace(string prefix, out bool thisScope)
        {
            Debug.Assert(prefix != null);
            thisScope = true;

            if (prefix == null || prefix.Length == 0)
            {
                return(_defaultNS);
            }
            else
            {
                if (Ref.Equal(prefix, _atoms.Xml))
                {
                    return(_atoms.XmlNamespace);
                }
                else if (Ref.Equal(prefix, _atoms.Xmlns))
                {
                    return(_atoms.XmlnsNamespace);
                }

                for (int i = _elementScopesStack.Length - 1; i >= 0; i--)
                {
                    Debug.Assert(_elementScopesStack[i] is OutputScope);
                    OutputScope elementScope = (OutputScope)_elementScopesStack[i];

                    string nspace = elementScope.ResolveAtom(prefix);
                    if (nspace != null)
                    {
                        thisScope = (i == _elementScopesStack.Length - 1);
                        return(nspace);
                    }
                }
            }

            return(null);
        }
Example #28
0
 public bool ParseReaderNode()
 {
     if (this.reader.Depth > this.markupDepth)
     {
         if (this.processMarkup)
         {
             this.ProcessAppInfoDocMarkup(false);
         }
         return(true);
     }
     if (this.reader.NodeType == XmlNodeType.Element)
     {
         if (this.builder.ProcessElement(this.reader.Prefix, this.reader.LocalName, this.reader.NamespaceURI))
         {
             this.namespaceManager.PushScope();
             if (this.reader.MoveToFirstAttribute())
             {
                 do
                 {
                     this.builder.ProcessAttribute(this.reader.Prefix, this.reader.LocalName, this.reader.NamespaceURI, this.reader.Value);
                     if (Ref.Equal(this.reader.NamespaceURI, this.schemaNames.NsXmlNs) && this.isProcessNamespaces)
                     {
                         this.namespaceManager.AddNamespace((this.reader.Prefix.Length == 0) ? string.Empty : this.reader.LocalName, this.reader.Value);
                     }
                 }while (this.reader.MoveToNextAttribute());
                 this.reader.MoveToElement();
             }
             this.builder.StartChildren();
             if (this.reader.IsEmptyElement)
             {
                 this.namespaceManager.PopScope();
                 this.builder.EndChildren();
                 if (this.reader.Depth == this.schemaXmlDepth)
                 {
                     return(false);
                 }
             }
             else if (!this.builder.IsContentParsed())
             {
                 this.markupDepth   = this.reader.Depth;
                 this.processMarkup = true;
                 if (this.annotationNSManager == null)
                 {
                     this.annotationNSManager = new XmlNamespaceManager(this.nameTable);
                     this.xmlns = this.nameTable.Add("xmlns");
                 }
                 this.ProcessAppInfoDocMarkup(true);
             }
         }
         else if (!this.reader.IsEmptyElement)
         {
             this.markupDepth   = this.reader.Depth;
             this.processMarkup = false;
         }
     }
     else if (this.reader.NodeType == XmlNodeType.Text)
     {
         if (!this.xmlCharType.IsOnlyWhitespace(this.reader.Value))
         {
             this.builder.ProcessCData(this.reader.Value);
         }
     }
     else if (((this.reader.NodeType == XmlNodeType.EntityReference) || (this.reader.NodeType == XmlNodeType.SignificantWhitespace)) || (this.reader.NodeType == XmlNodeType.CDATA))
     {
         this.builder.ProcessCData(this.reader.Value);
     }
     else if (this.reader.NodeType == XmlNodeType.EndElement)
     {
         if (this.reader.Depth == this.markupDepth)
         {
             if (this.processMarkup)
             {
                 XmlNodeList childNodes = this.parentNode.ChildNodes;
                 XmlNode[]   markup     = new XmlNode[childNodes.Count];
                 for (int i = 0; i < childNodes.Count; i++)
                 {
                     markup[i] = childNodes[i];
                 }
                 this.builder.ProcessMarkup(markup);
                 this.namespaceManager.PopScope();
                 this.builder.EndChildren();
             }
             this.markupDepth = 0x7fffffff;
         }
         else
         {
             this.namespaceManager.PopScope();
             this.builder.EndChildren();
         }
         if (this.reader.Depth == this.schemaXmlDepth)
         {
             return(false);
         }
     }
     return(true);
 }
        private XmlElement LoadElementNode(bool root)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element);

            XmlReader r             = reader;
            bool      fEmptyElement = r.IsEmptyElement;

            XmlElement element = dummyDocument.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI);

            element.IsEmpty = fEmptyElement;

            if (root)
            {
                parentNode = element;
            }
            else
            {
                XmlAttributeCollection attributes = element.Attributes;
                if (r.MoveToFirstAttribute())
                {
                    do
                    {
                        if (Ref.Equal(r.NamespaceURI, schemaNames.NsXmlNs))   //Namespace Attribute
                        {
                            annotationNSManager.AddNamespace(r.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
                        }
                        XmlAttribute attr = LoadAttributeNode();
                        attributes.Append(attr);
                    } while(r.MoveToNextAttribute());
                }
                r.MoveToElement();
                string ns = annotationNSManager.LookupNamespace(r.Prefix);
                if (ns == null)
                {
                    XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, namespaceManager.LookupNamespace(r.Prefix));
                    attributes.Append(attr);
                }
                else if (ns.Length == 0)   //string.Empty prefix is mapped to string.Empty NS by default
                {
                    string elemNS = namespaceManager.LookupNamespace(r.Prefix);
                    if (elemNS != string.Empty)
                    {
                        XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, elemNS);
                        attributes.Append(attr);
                    }
                }

                while (r.MoveToNextAttribute())
                {
                    if (r.Prefix.Length != 0)
                    {
                        string attNS = annotationNSManager.LookupNamespace(r.Prefix);
                        if (attNS == null)
                        {
                            XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, namespaceManager.LookupNamespace(r.Prefix));
                            attributes.Append(attr);
                        }
                    }
                }
                r.MoveToElement();

                parentNode.AppendChild(element);
                if (!r.IsEmptyElement)
                {
                    parentNode = element;
                }
            }
            return(element);
        }
 public bool ParseReaderNode()
 {
     if (reader.Depth > markupDepth)
     {
         if (processMarkup)
         {
             ProcessAppInfoDocMarkup(false);
         }
         return(true);
     }
     else if (reader.NodeType == XmlNodeType.Element)
     {
         if (builder.ProcessElement(reader.Prefix, reader.LocalName, reader.NamespaceURI))
         {
             namespaceManager.PushScope();
             if (reader.MoveToFirstAttribute())
             {
                 do
                 {
                     builder.ProcessAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
                     if (Ref.Equal(reader.NamespaceURI, schemaNames.NsXmlNs) && isProcessNamespaces)
                     {
                         namespaceManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
                     }
                 }while (reader.MoveToNextAttribute());
                 reader.MoveToElement(); // get back to the element
             }
             builder.StartChildren();
             if (reader.IsEmptyElement)
             {
                 namespaceManager.PopScope();
                 builder.EndChildren();
             }
             else if (!builder.IsContentParsed())   //AppInfo and Documentation
             {
                 markupDepth   = reader.Depth;
                 processMarkup = true;
                 if (annotationNSManager == null)
                 {
                     annotationNSManager = new XmlNamespaceManager(nameTable);
                     xmlns = nameTable.Add("xmlns");
                 }
                 ProcessAppInfoDocMarkup(true);
             }
         }
         else if (!reader.IsEmptyElement)   //UnsupportedElement in that context
         {
             markupDepth   = reader.Depth;
             processMarkup = false; //Hack to not process unsupported elements
         }
     }
     else if (reader.NodeType == XmlNodeType.Text ||
              reader.NodeType == XmlNodeType.EntityReference ||
              reader.NodeType == XmlNodeType.SignificantWhitespace ||
              reader.NodeType == XmlNodeType.CDATA)
     {
         builder.ProcessCData(reader.Value);
     }
     else if (reader.NodeType == XmlNodeType.EndElement)
     {
         if (reader.Depth == markupDepth)
         {
             if (processMarkup)
             {
                 Debug.Assert(parentNode != null);
                 XmlNodeList list   = parentNode.ChildNodes;
                 XmlNode[]   markup = new XmlNode[list.Count];
                 for (int i = 0; i < list.Count; i++)
                 {
                     markup[i] = list[i];
                 }
                 builder.ProcessMarkup(markup);
                 namespaceManager.PopScope();
                 builder.EndChildren();
             }
             markupDepth = int.MaxValue;
         }
         else
         {
             namespaceManager.PopScope();
             builder.EndChildren();
         }
         if (reader.Depth == schemaXmlDepth)
         {
             return(false); // done
         }
     }
     return(true);
 }