public override void WriteEndElement() { bool isLeaf = cflag; CompleteElement(true); if (context.scopeFlag) NamespaceManager.PopScope(); if (SchemaInfo != null && SchemaInfo.SchemaElement != null) context.node.SchemaInfo = SchemaInfo; LastElementEnd = context.pos; if (!isLeaf) { m_pageFile[context.pos] = m_pageFile.Count + 1; m_pageFile.AddNode(-1, null, null); m_pageFile[m_pageFile.Count - 1] = LastElementEnd; } _parent = (DmContainer)context.node.ParentNode; context = context.parent; }
public XQueryDocumentBuilder(XQueryDocument doc) { m_document = doc; if (doc.pagefile == null) { m_pageFile = new PageFile(false); m_pageFile.HasSchemaInfo = true; doc.pagefile = m_pageFile; } else m_pageFile = doc.pagefile; NameTable = doc.nameTable; xmlns = NameTable.Get(XmlReservedNs.NsXmlNs); _state = WriteState.Start; if (doc.input == null) { _normalize = true; hs = new HashSet<object>(); NamespaceManager = new XmlNamespaceManager(NameTable); } SchemaInfo = null; DocumentRoot = new DmRoot(); _parent = DocumentRoot; _text = null; }
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; } }