Exemple #1
0
        public XmlNode _GetNode(string namespacePrefix, PathSlicer xpath)
        {
            XmlNode node = _GetNode(namespacePrefix, xpath.Path);

            if (node == null)  // if SelectSingleNode doesn't work, try finding the node 'manually'
            {
                RichXmlNode n2 = new RichXmlNode(_doc);
                foreach (string segment in xpath.Segments)
                {
                    n2 = new RichXmlNode(n2.FindChild(segment));
                    if (n2.Node == null)
                    {
                        break;
                    }
                }
                node = n2.Node;
            }
            return(node);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- _RussianDollTraversal -->
        /// <summary>
        ///      Creates a string like what the 'russian doll' version would be
        /// </summary>
        /// <remarks>
        ///      A 'Russian Doll' schema is one that uses no 'ref' atttributes, so everything is
        ///      in the form that the XML it validates or creates will be in
        /// </remarks>
        /// <param name="node"></param>
        /// <param name="level"></param>
        public string _RussianDollTraversal(XmlNode node, int level, string attrs)
        {
            RichXmlNode rxNode  = new RichXmlNode(node);
            string      margin  = rxNode.Margin(level);
            string      nodeTag = rxNode.Tag;
            string      str;

            rxNode.AttributeList();


            if (rxNode.HasChildNodes) // elements
            {
                // ----------------------------------------------------------------------
                //  Process the node
                // ----------------------------------------------------------------------
                string reference = rxNode.Attribute("name");
                string minBound  = rxNode.Attribute("minOccurs");
                string maxBound  = rxNode.Attribute("maxOccurs");


                //  Things to skip:
                if (level == 2 && _IsUsed(reference) || nodeTag == "xs:annotation")
                {
                    str = "";
                }
                else
                {
                    switch (level)
                    {
                    case 0: str = "";
                        break;

                    case 1: str = "<" + nodeTag + rxNode.AttributeString() + attrs + ">";
                        break;

                    default: str = margin + "<" + nodeTag + rxNode.AttributeString() + attrs + ">";
                        break;
                    }


                    // ------------------------------------------------------------------
                    //  Add element tags and recurse down one level
                    // ------------------------------------------------------------------
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        str += _RussianDollTraversal(childNode, level + 1, "");
                    }
                    if (level > 0)
                    {
                        str += margin + "</" + nodeTag + ">";
                    }
                }
            }
            else
            {
                // ----------------------------------------------------------------------
                //  Process the leaf: show it or continue into the ref - refs are leaves
                // ----------------------------------------------------------------------
                string reference = rxNode.Attribute("ref");
                if (reference == "")
                {
                    if (rxNode.NodeType == XmlNodeType.XmlDeclaration)
                    {
                        str = margin + "<?" + nodeTag + rxNode.AttributeString() + rxNode.LeafEnd();
                    }
                    else
                    {
                        str = margin + "<" + nodeTag + rxNode.AttributeString() + rxNode.LeafEnd();
                    }
                }
                else
                {
                    str = _RussianDollTraversal(_RefNode(reference, nodeTag), level
                                                , rxNode.MoreAttributes());
                }
            }


            return(str);
        }
 public RichXmlNode ReplaceChild(RichXmlNode node, RichXmlNode oldChild)
 {
     return(new RichXmlNode(_node.ReplaceChild(node.Node, oldChild.Node)));
 }
        //_node.WriteTo();
        //_node.WriteContentTo();


        // ----------------------------------------------------------------------------------------
        /// <!-- RemoveSelf -->
        /// <summary>
        ///      Removes this node and all of its sub nodes
        /// </summary>
        /// <param name="node"></param>
        public RichXmlNode RemoveSelf()
        {
            RichXmlNode parent = this.ParentNode;

            return(parent.RemoveChild(this));
        }
 public RichXmlNode RemoveChild(RichXmlNode node)
 {
     return(new RichXmlNode(_node.RemoveChild(node.Node)));
 }