K
Keith
Hi
How do I convert to following code to return a Dictionary referenced by the
key?
public List<KeyXpath> GetXPathExpressions()
{
try
{
var results = from xpaths in XDocumentObj.Descendants("value")
select new KeyXpath
{
Key = xpaths.Attribute("key").Value,
Xpath = xpaths.Attribute("xpath").Value
};
return results.ToList();
}
catch
{
return new List<KeyXpath>(0);
}
}
public class KeyXpath
{
public string Key { get; set; }
public string Xpath { get; set; }
}
The Xml file its reading looks like :
<?xml version="1.0" encoding="utf-8" ?>
<DataMining>
<!--
key = this is the value that the component extracting data uses to find the
xpath
xpath = a valid XPath expression to the data in the Xml document
-->
<value key="two" xpath="//one/two"/>
<value key="one" xpath="//three[@four = 'five']" />
</DataMining>
I've been looking around and trying to find a solution for a couple of weeks
now. Its easy to create a dictionary using key that is a property of the
object to be stored in the dictionary but I couldn't adapt this code to work
with a key value string pair.
The function signiture should look like :
public Dictionary<string, string> GetExpressions()
Can someone help me please.
Thanks
K
How do I convert to following code to return a Dictionary referenced by the
key?
public List<KeyXpath> GetXPathExpressions()
{
try
{
var results = from xpaths in XDocumentObj.Descendants("value")
select new KeyXpath
{
Key = xpaths.Attribute("key").Value,
Xpath = xpaths.Attribute("xpath").Value
};
return results.ToList();
}
catch
{
return new List<KeyXpath>(0);
}
}
public class KeyXpath
{
public string Key { get; set; }
public string Xpath { get; set; }
}
The Xml file its reading looks like :
<?xml version="1.0" encoding="utf-8" ?>
<DataMining>
<!--
key = this is the value that the component extracting data uses to find the
xpath
xpath = a valid XPath expression to the data in the Xml document
-->
<value key="two" xpath="//one/two"/>
<value key="one" xpath="//three[@four = 'five']" />
</DataMining>
I've been looking around and trying to find a solution for a couple of weeks
now. Its easy to create a dictionary using key that is a property of the
object to be stored in the dictionary but I couldn't adapt this code to work
with a key value string pair.
The function signiture should look like :
public Dictionary<string, string> GetExpressions()
Can someone help me please.
Thanks
K