Esempio n. 1
0
 /// <summary>
 ///     重写构造函数(如果url为空,过滤掉prefix)
 /// </summary>
 /// <param name="xmlNode"></param>
 public Element(XmlNode xmlNode, ILocator locator = null)
 {
     uri         = xmlNode.NamespaceURI; //.BaseURI;
     tagName     = string.IsNullOrEmpty(uri) ? xmlNode.Name /*.Replace(xmlNode.Prefix + ":", "")*/ : xmlNode.LocalName;
     RootXmlNode = xmlNode;
     if (xmlNode.Attributes != null)
     {
         foreach (XmlAttribute attribute in xmlNode.Attributes)
         {
             var attributeUri = attribute.NamespaceURI; //.BaseURI;
             var name         = string.IsNullOrEmpty(attributeUri)
                 ? attribute.Name                       //.Replace(attribute.Prefix + ":", "")
                 : attribute.LocalName;
             var value = attribute.Value;
             AttributeMap[ComposeMapKey(attributeUri, name)] = new Attribute(name, value, attributeUri);
         }
     }
     if (locator != null)
     {
         line   = locator.GetLineNumber();
         column = locator.GetColumnNumber();
     }
     if (xmlNode.ChildNodes.Count > 0)
     {
         foreach (XmlNode item in xmlNode.ChildNodes)
         {
             ElementsRenamed.Add(new Element(item, null));
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        ///     Element构造函数
        /// </summary>
        /// <param name="uri">资源地址</param>
        /// <param name="localName">本地名称(uri有值时tagname为此值)</param>
        /// <param name="qName">q名称(uri为空时tagname为此值)</param>
        /// <param name="attributes">特性集合,可以为null</param>
        /// <param name="locator">定位可以为null</param>
        public Element(string uri, string localName, string qName, IAttributes attributes, ILocator locator)
        {
            this.uri = uri;
            tagName  = string.IsNullOrEmpty(uri) ? qName : localName;

            if (attributes != null)
            {
                for (var i = 0; i < attributes.GetLength(); i++)
                {
                    var attributeUri = attributes.GetUri(i);
                    var name         = string.IsNullOrEmpty(attributeUri) ? attributes.GetQName(i) : attributes.GetLocalName(i);
                    var value        = attributes.GetValue(i);
                    AttributeMap[ComposeMapKey(attributeUri, name)] = new Attribute(name, value, attributeUri);
                }
            }

            if (locator != null)
            {
                line   = locator.GetLineNumber();   //.LineNumber;
                column = locator.GetColumnNumber(); //.ColumnNumber;
            }
        }