[Mono-bugs] [Bug 499970] New: Xmlnode attribute and inertext seem broken

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Apr 30 19:51:46 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=499970


           Summary: Xmlnode attribute and inertext seem broken
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: x86-64
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: surfzoid2002 at yahoo.fr
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.8)
Gecko/2009032803 Mandriva/1.9.0.8-1mdv2009.1 (2009.1) Firefox/3.0.8

A simple parsing function don't give the same result under win/.Net and
nux/Mono.

Reproducible: Always

Steps to Reproduce:
1. use the folowing code without the "item.Attributes != null &&" in the if,
with the XML example i give,to feed a treeview, you will have an "Object
reference not set to an instance of an object "


        public static TreeNode XmlToTreeNode(string leXml)

        {

            TreeNode Result = null;

            try

            {

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(leXml);

                XmlNode RootNde = doc.ChildNodes.Item(0);

                if (string.IsNullOrEmpty(RootNde.Name) == false) Result = new
TreeNode(RootNde.Name);

                foreach (XmlNode CurNode in RootNde.ChildNodes)

                {

                    if (string.IsNullOrEmpty(CurNode.Name) == false)

                    {

                        TreeNode Nde = new TreeNode(CurNode.Name);

                        Nde.Tag = CurNode.InnerText;

                        if (CurNode.Attributes.Count > 0)

                        {

                            string AttrName = CurNode.Attributes[0].Name;

                            string AttrVal = CurNode.Attributes[0].InnerText;

                            TreeNode ChildNde = null;

                            for (int i = 0; i < CurNode.Attributes.Count; i++)

                            {

                                ChildNde = new
TreeNode(CurNode.Attributes[i].Name);

                                ChildNde.Tag = CurNode.Attributes[i].InnerText;

                                Nde.Nodes.Add(ChildNde);

                            }

                        }



                        foreach (XmlNode item in CurNode.ChildNodes)

                        {

                            TreeNode Nde2 = new TreeNode(item.Name);

                            Nde2.Tag = item.InnerText;

                            if (item.Attributes != null &&
item.Attributes.Count > 0)

                            {

                                string AttrName2 = item.Attributes[0].Name;

                                string AttrVal2 = item.Attributes[0].InnerText;

                                TreeNode ChildNde2 = null;

                                for (int i = 0; i < item.Attributes.Count; i++)

                                {

                                    ChildNde2 = new
TreeNode(item.Attributes[i].Name);

                                    ChildNde2.Tag =
item.Attributes[i].InnerText;

                                    Nde2.Nodes.Add(ChildNde2);

                                }

                            }

                            Nde.Nodes.Add(Nde2);

                        }

                        Result.Nodes.Add(Nde);

                    }



                }

            }

            catch (Exception Ex)

            {

                Console.WriteLine("{0} {1} {2}",
Ex.Message,Environment.NewLine, Ex.StackTrace);

                TreeNode Err = new TreeNode("Error");

                return Err;

            }

            return Result;

        }

XML data example to use :
<person>
<login>rwooninck</login>
<email>tittiatcoke at gmail.com</email>
<realname>Raymond Wooninck</realname>
−
<watchlist>
<project name="KDE:KDE4:Factory:Desktop"/>
<project name="KDE:KDE4:UNSTABLE:Desktop"/>
<project name="openSUSE:Factory"/>
<project name="openSUSE:Factory:Contrib"/>
</watchlist>
</person>
Actual Results:  
see the screenshot when using "item.Attributes != null &&" to prevent first
monobug and see the "extra" "#text".

Expected Results:  
no more "Object reference not set to an instance of an object " and "extra"
"#text" to display same result as windows/.Net

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list