示例#1
0
        private void PushElement(XElement e)
        {
            _resolver.PushScope();
            XAttribute a = e.lastAttr;

            if (a != null)
            {
                do
                {
                    a = a.next;
                    if (a.IsNamespaceDeclaration)
                    {
                        _resolver.Add(a.Name.NamespaceName.Length == 0 ? string.Empty : a.Name.LocalName, XNamespace.Get(a.Value));
                    }
                } while (a != e.lastAttr);
            }
        }
示例#2
0
 private void PushElement()
 {
     _resolver.PushScope();
     foreach (XAttribute a in _attributes)
     {
         if (a.IsNamespaceDeclaration)
         {
             _resolver.Add(a.Name.NamespaceName.Length == 0 ? string.Empty : a.Name.LocalName, XNamespace.Get(a.Value));
         }
     }
 }
示例#3
0
 public override void WriteStartElement(string prefix, string localName, string namespaceName)
 {
     AddNode(new XElement(XNamespace.Get(namespaceName).GetName(localName)));
 }
示例#4
0
 private void PushAncestors(XElement e)
 {
     while (true)
     {
         e = e.parent as XElement;
         if (e == null)
         {
             break;
         }
         XAttribute a = e.lastAttr;
         if (a != null)
         {
             do
             {
                 a = a.next;
                 if (a.IsNamespaceDeclaration)
                 {
                     _resolver.AddFirst(a.Name.NamespaceName.Length == 0 ? string.Empty : a.Name.LocalName, XNamespace.Get(a.Value));
                 }
             } while (a != e.lastAttr);
         }
     }
 }
示例#5
0
 /// <summary>
 /// Returns an <see cref="XName"/> object from a local name and a namespace.
 /// </summary>
 /// <param name="localName">A local (unqualified) name.</param>
 /// <param name="namespaceName">An XML namespace.</param>
 /// <returns>An XName object created from the specified local name and namespace.</returns>
 public static XName Get(string localName, string namespaceName)
 {
     return(XNamespace.Get(namespaceName).GetName(localName));
 }
示例#6
0
        bool ReadPrologUntil(XElement source, XName match)
        {
            if (_reader.ReadState != ReadState.Interactive)
            {
                throw new InvalidOperationException("The reader state should be Interactive.");
            }
            do
            {
                switch (_reader.NodeType)
                {
                case XmlNodeType.Element:
                    XName name = XNamespace.Get(_reader.NamespaceURI).GetName(_reader.LocalName);
                    if (name == match)
                    {
                        return(true);
                    }
                    XElement e = new XElement(name);
                    if (_reader.MoveToFirstAttribute())
                    {
                        do
                        {
                            XNamespace ns = _reader.Prefix.Length == 0 ? XNamespace.None : XNamespace.Get(_reader.NamespaceURI);
                            e.Add(new XAttribute(ns.GetName(_reader.LocalName), _reader.Value));
                        } while (_reader.MoveToNextAttribute());
                        _reader.MoveToElement();
                    }
                    source.Add(e);
                    if (!_reader.IsEmptyElement)
                    {
                        _reader.Read();
                        ReadContent(e);
                    }
                    break;

                case XmlNodeType.EndElement:
                    return(false);

                case XmlNodeType.Text:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.Whitespace:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.DocumentType:
                    break;

                case XmlNodeType.EntityReference:
                    if (!_reader.CanResolveEntity)
                    {
                        throw new InvalidOperationException("The reader cannot resolve entity references.");
                    }
                    _reader.ResolveEntity();
                    break;

                case XmlNodeType.EndEntity:
                    break;

                default:
                    throw new InvalidOperationException(String.Format("The reader should not be on a node of type '{0}'.", _reader.NodeType));
                }
            } while (_reader.Read());
            return(false);
        }
 public XmlNamespaceHelper(XDocument xml, string defaultPrefix)
 {
     _defaultPrefix = defaultPrefix;
     _nsm           = new XmlNamespaceManager(new NameTable());
     xml.Root.Attributes()
     .Where(a => a.IsNamespaceDeclaration)
     .GroupBy(a => a.Name.Namespace == XNamespace.None ? defaultPrefix : a.Name.LocalName, a => XNamespace.Get(a.Value))
     .ToList()
     .ForEach(ns => _nsm.AddNamespace(string.IsNullOrWhiteSpace(ns.Key) ? defaultPrefix : ns.Key, ns.First().NamespaceName));
     _defaultToken = _nsm.HasNamespace(defaultPrefix) ? defaultPrefix + ":" : "";
 }
示例#8
0
 public XmlNamespaceHelper(XDocument xml, string defaultPrefix)
 {
     DefaultPrefix    = defaultPrefix;
     NamespaceManager = new XmlNamespaceManager(new NameTable());
     xml.XPathSelectElements("//*").SelectMany(e => e.Attributes())
     .Where(a => a.IsNamespaceDeclaration)
     .GroupBy(a => a.Name.Namespace == XNamespace.None ? defaultPrefix : a.Name.LocalName, a => XNamespace.Get(a.Value))
     .ToList()
     .ForEach(ns => NamespaceManager.AddNamespace(string.IsNullOrWhiteSpace(ns.Key) ? defaultPrefix : ns.Key, ns.First().NamespaceName));
     DefaultToken = NamespaceManager.HasNamespace(defaultPrefix) ? defaultPrefix + ":" : "";
 }
示例#9
0
 private void PushElement()
 {
     this.resolver.PushScope();
     foreach (XAttribute attribute in this.attributes)
     {
         if (attribute.IsNamespaceDeclaration)
         {
             this.resolver.Add((attribute.Name.NamespaceName.Length == 0) ? string.Empty : attribute.Name.LocalName, XNamespace.Get(attribute.Value));
         }
     }
 }