Paula DiTallo
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.ReadFromDictinaryB yKey("Posi tion") where "Position" is a string key. The line xdoc.Save(Console.Out) works. The output of the data is in the attached file.
In the next set of lines, I look to see what the nodes are. The nodes that output from here are "xml" and "feed".
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.
I am confused about the structure of this doc--I thought that I would see the nodes: feed/entry/content/propert ies-- with the elements under properties.
Can someone offer direction/advice on what it is I haven't got right?
Positions.xml
I am trying to export an xml document from a Dictionary/hastable in odataSF.ReadFromDictinaryB
XmlDocument xdoc = new XmlDocument();
xdoc = odataSF.ReadFromDictionaryByKey("Position");
xdoc.Save(Console.Out);
Console.WriteLine("\n");
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");
}
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);
}
I am confused about the structure of this doc--I thought that I would see the nodes: feed/entry/content/propert
Can someone offer direction/advice on what it is I haven't got right?
Positions.xml
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliantly done @Saige! :)
Not a problem.
-saige-
-saige-