AddAttrXmlName() private method

private AddAttrXmlName ( string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo ) : XmlName
prefix string
localName string
namespaceURI string
schemaInfo IXmlSchemaInfo
return XmlName
コード例 #1
0
        private void ValidateNode(XmlNode node)
        {
            _currentNode = node;
            switch (_currentNode.NodeType)
            {
            case XmlNodeType.Document:
                XmlElement docElem = ((XmlDocument)node).DocumentElement;
                if (docElem == null)
                {
                    throw new InvalidOperationException(SR.Format(SR.Xml_InvalidXmlDocument, SR.Xdom_NoRootEle));
                }
                ValidateNode(docElem);
                break;

            case XmlNodeType.DocumentFragment:
            case XmlNodeType.EntityReference:
                for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    ValidateNode(child);
                }
                break;

            case XmlNodeType.Element:
                ValidateElement();
                break;

            case XmlNodeType.Attribute:     //Top-level attribute
                XmlAttribute attr = _currentNode as XmlAttribute;
                _validator.ValidateAttribute(attr.LocalName, attr.NamespaceURI, _nodeValueGetter, _attributeSchemaInfo);
                if (_psviAugmentation)
                {
                    attr.XmlName = _document.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, _attributeSchemaInfo);
                }
                break;

            case XmlNodeType.Text:
                _validator.ValidateText(_nodeValueGetter);
                break;

            case XmlNodeType.CDATA:
                _validator.ValidateText(_nodeValueGetter);
                break;

            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                _validator.ValidateWhitespace(_nodeValueGetter);
                break;

            case XmlNodeType.Comment:
            case XmlNodeType.ProcessingInstruction:
                break;

            default:
                throw new InvalidOperationException(SR.Format(SR.Xml_UnexpectedNodeType, new string[] { _currentNode.NodeType.ToString() }));
            }
        }
コード例 #2
0
ファイル: XmlLoader.cs プロジェクト: rsumner31/corefx2
        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);
        }
コード例 #3
0
 protected internal XmlAttribute(string prefix, string localName, string namespaceURI, XmlDocument doc)
     : this(doc.AddAttrXmlName(prefix, localName, namespaceURI), doc)
 {
 }
コード例 #4
0
 protected internal XmlAttribute( string prefix, string localName, string namespaceURI, XmlDocument doc )
 : this(doc.AddAttrXmlName(prefix, localName, namespaceURI, null), doc) {
 }
コード例 #5
0
        private void ValidateNode(XmlNode node)
        {
            currentNode = node;
            switch (currentNode.NodeType)
            {
            case XmlNodeType.Document:
                XmlElement docElem = ((XmlDocument)node).DocumentElement;
                if (docElem == null)
                {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_InvalidXmlDocument, Res.GetString(Res.Xdom_NoRootEle)));
                }
                ValidateNode(docElem);
                break;

            case XmlNodeType.DocumentFragment:
            case XmlNodeType.EntityReference:
                for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
                {
                    ValidateNode(child);
                }
                break;

            case XmlNodeType.Element:
                ValidateElement();
                break;

            case XmlNodeType.Attribute:     //Top-level attribute
                XmlAttribute attr = currentNode as XmlAttribute;
                validator.ValidateAttribute(attr.LocalName, attr.NamespaceURI, nodeValueGetter, attributeSchemaInfo);
                if (psviAugmentation)
                {
                    attr.XmlName = document.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, attributeSchemaInfo);
                }
                break;

            case XmlNodeType.Text:
                if (validator.CurrentContentType == XmlSchemaContentType.ElementOnly && XmlCharType.Instance.IsOnlyWhitespace(currentNode.Value))       //The text node could contain only whitespaces
                {
                    validator.ValidateWhitespace(nodeValueGetter);
                }
                else
                {
                    validator.ValidateText(nodeValueGetter);
                }
                break;

            case XmlNodeType.CDATA:
                validator.ValidateText(nodeValueGetter);
                break;

            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                validator.ValidateWhitespace(nodeValueGetter);
                break;

            case XmlNodeType.Comment:
            case XmlNodeType.ProcessingInstruction:
                break;

            default:
                throw new InvalidOperationException(Res.GetString(Res.Xml_UnexpectedNodeType, new string[] { currentNode.NodeType.ToString() }));
            }
        }