Link to home
Start Free TrialLog in
Avatar of Paula DiTallo
Paula DiTalloFlag for United States of America

asked on

c# XmlDocument node elements/attributes not visible from known nodes

Techies--
I am trying to export an xml document from a Dictionary/hastable in odataSF.ReadFromDictinaryByKey("Position") where "Position" is a string key. The line xdoc.Save(Console.Out) works. The output of the data is in the attached file.
               XmlDocument xdoc = new XmlDocument();
               xdoc = odataSF.ReadFromDictionaryByKey("Position");
               xdoc.Save(Console.Out);

               Console.WriteLine("\n");

Open in new window

     
                    
In the next set of lines, I look to see what the nodes are. The nodes that output from here are "xml" and "feed".

			   
               //capture nodes - start at the very beginning "/"
               List<string> nodeNames = new List<string>();
               foreach (System.Xml.XmlNode node in xdoc.SelectNodes("/"))
               {
                   foreach (System.Xml.XmlNode child in node.ChildNodes)
                   {
                       if (!nodeNames.Contains(child.Name)) nodeNames.Add(child.Name);
                       
                   }
               }
			   
               Console.WriteLine("Names of Nodes: \n");
               foreach (string name in nodeNames)
               {
                   Console.WriteLine("Node: " + name + "\n");
               }

Open in new window


Here is where I am attempting to get specific values back out of the document. No errors, but nothing is found. Doesn't matter whether I put in xml, feed, etc. Nothing
is found.

               XmlNodeList xnList = xdoc.SelectNodes("/xml");
               foreach (XmlNode xn in xnList)
               {
                   string jobTitle = xn["jobTitle"].InnerText;
                   string code = xn["code"].InnerText;

                   Console.WriteLine("Elements: {0} {1}", jobTitle, code);
               }

Open in new window


I am confused about the structure of this doc--I thought that I would see the nodes: feed/entry/content/properties-- with the elements under properties.
Can someone offer direction/advice on what it is I haven't got right?
Positions.xml
Avatar of ste5an
ste5an
Flag of Germany image

The problem is that yor XML uses a default namespace. Thus your selector can not find it, cause it does not know it. Here is an example showing how to specify it.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paula DiTallo

ASKER

Brilliantly done @Saige! :)
Not a problem.

-saige-