Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

Should be simple LINQ to XML

$
0
0

Consider I have a XML something like this   ( Goal is to return a dictionary with keyValuePair of key =owner, and value =element name ( ie personal or business )  - how do I get at just the childNode Name  ??

<cars>

<car ownerID ='1234'>

<personal someattribute="">

</car>

<car ownerID ='1445'>

<business someattribute="">

</car>

</cars>

public Dictionary<string,string> GetElementsAttributeWithFirstNodeName(string XMLFragSource, string elementName, string attributeName)
        {
            var myKeyValReturn   = new Dictionary<string, string> ();  // once subnode name can be returned.


            XElement allData = XElement.Parse(XMLFragSource);
            if (allData != null)
            {
                IEnumerable<XElement> Test_Elements = allData.Descendants(elementName);
                foreach (XElement telement in Test_Elements)
               // retVal.Add(telement.Attribute(attributeName).Value + "type=" + telement.FirstNode);  // want nodeName of firstNode
                myKeyValReturn.Add(telement.Attribute(attributeName).Value, "looking for telement.FirstNode.Name");
            }

            return myKeyValReturn;

        }

Thanks !!!


andrew


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>