コード例 #1
0
        public override void asDataElement(DataElement parent, object dataBuffer)
        {
            if (!(parent is Dom.String))
            {
                throw new PeachException("Error, XmlAnalyzer analyzer only operates on String elements!");
            }

            var strElement = parent as Dom.String;

            if (string.IsNullOrEmpty((string)strElement.InternalValue))
            {
                return;
            }

            var doc = new XmlDocument();

            try
            {
                doc.LoadXml((string)strElement.InternalValue);
            }
            catch (Exception ex)
            {
                throw new PeachException("Errorm XmlAnalyzer failed to analyze element '" + parent.name + "'.  " + ex.Message, ex);
            }

            Dom.XmlElement xmlElement = null;

            foreach (XmlNode node in doc.ChildNodes)
            {
                if (node is XmlDeclaration || node is XmlComment)
                {
                    continue;
                }

                if (node.Name.StartsWith("#"))
                {
                    continue;
                }

                xmlElement = handleXmlNode(node, parent.name);
            }

            xmlElement.parent = parent.parent;

            parent.parent[parent.name] = xmlElement;
        }
コード例 #2
0
ファイル: XmlAnalyzer.cs プロジェクト: 751620780/Peach
        public override void asDataElement(DataElement parent, Dictionary <DataElement, Position> positions)
        {
            var strElement = parent as Dom.String;

            if (strElement == null)
            {
                throw new PeachException("Error, XmlAnalyzer analyzer only operates on String elements!");
            }

            var value = (string)strElement.InternalValue;

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            var doc = new XmlDocument();

            try
            {
                doc.LoadXml(value);
            }
            catch (Exception ex)
            {
                throw new PeachException("Error, XmlAnalyzer failed to analyze element '" + parent.name + "'.  " + ex.Message, ex);
            }

            var elem = new Dom.XmlElement(strElement.name);

            foreach (XmlNode node in doc.ChildNodes)
            {
                handleXmlNode(elem, node, strElement.stringType);
            }

            var decl = doc.FirstChild as XmlDeclaration;

            if (decl != null)
            {
                elem.version    = decl.Version;
                elem.encoding   = decl.Encoding;
                elem.standalone = decl.Standalone;
            }

            parent.parent[parent.name] = elem;
        }
コード例 #3
0
ファイル: XmlAnalyzer.cs プロジェクト: 751620780/Peach
        protected void handleXmlNode(Dom.XmlElement elem, XmlNode node, StringType type)
        {
            if (node is XmlComment || node is XmlDeclaration)
            {
                return;
            }

            elem.elementName = node.Name;
            elem.ns          = node.NamespaceURI;

            foreach (System.Xml.XmlAttribute attr in node.Attributes)
            {
                var strElem  = makeString("value", attr.Value, type);
                var attrName = elem.UniqueName(attr.Name.Replace(':', '_'));
                var attrElem = new Dom.XmlAttribute(attrName)
                {
                    attributeName = attr.Name,
                    ns            = attr.NamespaceURI,
                };

                attrElem.Add(strElem);
                elem.Add(attrElem);
            }

            foreach (System.Xml.XmlNode child in node.ChildNodes)
            {
                if (child.Name == "#text")
                {
                    var str = makeString(child.Name, child.Value, type);
                    elem.Add(str);
                }
                else if (!child.Name.StartsWith("#"))
                {
                    var childName = elem.UniqueName(child.Name.Replace(':', '_'));
                    var childElem = new Dom.XmlElement(childName);

                    elem.Add(childElem);

                    handleXmlNode(childElem, child, type);
                }
            }
        }
コード例 #4
0
        protected Dom.XmlElement handleXmlNode(XmlNode node, string name)
        {
            Dom.XmlElement elem = null;

            if (name != null)
            {
                elem = new Dom.XmlElement(name);
            }
            else
            {
                elem = new Dom.XmlElement();
            }

            elem.elementName = node.Name;
            elem.ns          = node.NamespaceURI;

            foreach (System.Xml.XmlAttribute attrib in node.Attributes)
            {
                elem.Add(handleXmlAttribute(attrib));
            }

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.Name == "#text")
                {
                    var str = new Dom.String();
                    str.DefaultValue = new Variant(child.Value);
                    elem.Add(str);
                }
                else if (!child.Name.StartsWith("#"))
                {
                    elem.Add(handleXmlNode(child, null));
                }
            }

            return(elem);
        }