コード例 #1
0
 private void CompleteElement(bool isElemEnd)
 {
     if (cflag)
     {
         int pos = -1;
         if (context.parent != null)
             pos = context.parent.pos;
         context.node.IndexNode(m_pageFile.Count);
         m_pageFile.AddNode(pos, _parent = context.node, context.element);
         if (isElemEnd)
         {
             if (_text != null)
             {
                 context.element._value = _text;
                 m_pageFile[context.pos] = PageFile.MixedLeaf;
                 _parent.CreateChildText();
                 _text = null;
             }
             else
                 m_pageFile[context.pos] = PageFile.Leaf;
         }
         else
         {
             m_pageFile[context.pos] = 0;
             if (_text != null)
             {
                 DmText node = (DmText)_parent.CreateChildText();
                 node.IndexNode(m_pageFile.Count);
                 m_pageFile.AddNode(context.pos, node, new XdmText(_text));
                 _text = null;
             }
         }
         if (NamespaceManager != null)
         {
             IDictionary<string, string> dict = NamespaceManager.GetNamespacesInScope(XmlNamespaceScope.Local);
             string prefix = context.node.Prefix;
             if (prefix != "" && !dict.ContainsKey(prefix))
             {
                 WriteStartAttribute("xmlns", prefix, xmlns);
                 WriteString(context.node.NamespaceURI);
                 WriteEndAttribute();
             }
             XdmAttribute curr = context.element._attributes;
             while (curr != null)
             {
                 prefix = curr._dm.Prefix;
                 if (prefix != "")
                 {
                     dict = NamespaceManager.GetNamespacesInScope(XmlNamespaceScope.Local);
                     if (!dict.ContainsKey(prefix))
                     {
                         WriteStartAttribute("xmlns", prefix, xmlns);
                         WriteString(curr._dm.NamespaceURI);
                         WriteEndAttribute();
                     }
                 }
                 curr = curr._next;
             }
             if (_stripNamespace)
             {
                 List<XdmNamespace> nodes = new List<XdmNamespace>();
                 for (XdmNamespace ns1 = context.element._ns; ns1 != null; ns1 = ns1._next)
                 {
                     if (ns1._value == context.node.NamespaceURI ||
                         (NamespaceInheritanceMode == NamespaceInheritanceMode.Inherit &&
                             context.inheritedScope.ContainsKey(ns1._name)))
                         nodes.Add(ns1);
                     else
                     {
                         for (XdmAttribute atr = context.element._attributes; atr != null; atr = atr._next)
                         {
                             if (atr._dm.NamespaceURI == ns1._value)
                             {
                                 nodes.Add(ns1);
                                 break;
                             }
                         }
                     }
                 }
                 context.element._ns = ns = null;
                 foreach (XdmNamespace ns1 in nodes)
                 {
                     if (ns == null)
                         context.element._ns = ns = ns1;
                     else
                         ns._next = ns1;
                     ns1._next = null;
                 }
             }
             if (NamespaceInheritanceMode == NamespaceInheritanceMode.Inherit)
             {
                 dict = NamespaceManager.GetNamespacesInScope(XmlNamespaceScope.Local);
                 foreach (KeyValuePair<string, string> kvp in context.inheritedScope)
                 {
                     if (kvp.Key != "" && !(context.scopeFlag && dict.ContainsKey(kvp.Key)))
                     {
                         WriteStartAttribute("xmlns", kvp.Key, xmlns);
                         WriteString(kvp.Value);
                         WriteEndAttribute();
                     }
                 }
             }
         }
         attr = null;
         ns = null;
         if (hs != null)
             hs.Clear();
         cflag = false;
     }
 }
コード例 #2
0
 public override void WriteStartAttribute(string prefix, string localName, string namespaceUri)
 {
     if (context == null)
         throw new XQueryException(Properties.Resources.InvalidAttributeSequence);
     if (prefix == null)
         prefix = String.Empty;
     if (localName == null)
         throw new ArgumentException();
     if (namespaceUri == null)
         namespaceUri = String.Empty;
     if (!cflag || _text != null)
         throw new XQueryException(Properties.Resources.XQTY0024, new XmlQualifiedName(localName, namespaceUri));
     _state = WriteState.Attribute;
     _attr_text = null;
     DmNode node = context.node;
     XdmElement element = context.element;
     if (namespaceUri == xmlns)
     {
         ns2 = new XdmNamespace();
         ns2._name = String.IsNullOrEmpty(prefix) ? 
             String.Empty : localName;
         nsflag = true;
         if (NamespaceManager != null)
         {
             if (!context.scopeFlag)
             {
                 NamespaceManager.PushScope();
                 context.scopeFlag = true;
             }
         }
     }
     else
     {
         if (attr == null)
             element._attributes = attr = new XdmAttribute();
         else
         {
             XdmAttribute tmp = new XdmAttribute();
             attr._next = tmp;
             attr = tmp;
         }
         if (NamespaceManager != null && prefix != "")
         {
             string ns = NamespaceManager.LookupNamespace(prefix);
             if (ns != null && ns != namespaceUri)
             {
                 prefix = NamespaceManager.LookupPrefix(namespaceUri);
                 if (prefix == null)
                 {   // Generate new prefix
                     int k = 1;
                     do
                     {
                         prefix = String.Format("ns{0}", k++);
                     }
                     while (NamespaceManager.LookupNamespace(prefix) != null);
                     NamespaceManager.AddNamespace(prefix, namespaceUri);
                 }
             }
         }
         DmQName name = new DmQName(prefix, localName, namespaceUri, NameTable);
         attr._dm = (DmAttribute)context.node.CreateAttribute(name);
         nsflag = false;
         if (hs != null)
         {
             if (hs.Contains(name))
                 throw new XQueryException(Properties.Resources.XQDY0025,
                     new XmlQualifiedName(node.LocalName, node.NamespaceURI), 
                     new XmlQualifiedName(localName, namespaceUri));
             hs.Add(name);
         }
     }
 }
コード例 #3
0
        public override void WriteEndAttribute()
        {
            _state = WriteState.Element;
            string value = _attr_text != null ? 
                _attr_text : String.Empty;
            _attr_text = null;
            if (nsflag)
            {      
                ns2._value = value;
                if (context.node.Prefix == ns2._name && context.node.NamespaceURI != ns2._value)
                {
                    context.node = (DmElement)_parent.CreateChild(new DmQName(context.node.Prefix, 
                        context.node.LocalName, ns2._value, NameTable));
                    for (XdmAttribute attr = context.element._attributes; attr != null; attr = attr._next)
                    {
                        DmAttribute src = attr._dm;
                        attr._dm = (DmAttribute)context.node.CreateAttribute(src.QName);
                        attr._dm.SchemaInfo = src.SchemaInfo;
                        attr._dm.IsId = src.IsId;
                    }
                }
                if (context.scopeFlag)
                {
                    if (NamespaceInheritanceMode != NamespaceInheritanceMode.Inherit && 
                        NamespaceManager.LookupNamespace(ns2._name) == ns2._value)
                        return;
                    NamespaceManager.AddNamespace(ns2._name, ns2._value);
                }
                if (hs != null)
                {
                    if (hs.Contains(ns2._name))
                        throw new XQueryException(Properties.Resources.XQDY0025,
                            new XmlQualifiedName(context.node.LocalName, context.node.NamespaceURI), ns2._name);
                    hs.Add(ns2._name);
                }
                if (ns == null)
                    context.element._ns = ns2;
                else
                    ns._next = ns2;
                ns = ns2;
            }
            else
            {
                if (_normalize)
                {
                    if ((attr._dm.LocalName == "id" && attr._dm.NamespaceURI == XmlReservedNs.NsXml) ||
                        (SchemaInfo != null && SchemaInfo.SchemaType.TypeCode == XmlTypeCode.Id))
                        value = XQueryFuncs.NormalizeSpace(value);
                }
                attr._value = value;
                if (SchemaInfo != null && SchemaInfo.SchemaAttribute != null)
                    attr._dm.SchemaInfo = SchemaInfo;

            }            
        }
コード例 #4
0
 public override void Load(XdmReader reader)
 {
     base.Load(reader);
     XdmNamespace ns = null;
     while (true)
     {
         if (!reader.ReadBoolean())
             break;
         XdmNamespace curr = new XdmNamespace();
         curr.Load(reader);
         if (ns == null)
             _ns = ns = curr;
         else
         {
             ns._next = curr;
             ns = curr;
         }
     }
     XdmAttribute attr = null;
     while (true)
     {
         if (!reader.ReadBoolean())
             break;
         XdmAttribute curr = new XdmAttribute();
         curr.Load(reader);
         if (attr == null)
             _attributes = attr = curr;
         else
         {
             attr._next = curr;
             attr = curr;
         }
     }            
 }