I am trying to get values from an XML document using XDocument and XElement. I am trying to get three values, however when I try to return them, they are merged together as one value. Here is the XML I am searching:
<create_maint_traveler>
<Paths>
<outputPath value="D:\Intercim\DNC_Share\itcm\DataInput\MCDHeaderDrop\" />
<outputPath_today value="D:\Intercim\DNC_Share\itcm\DataInput\Today\" />
<log value="D:\Intercim\DNC_Share\itcm\Log\CreateMaintLog.log" />
</Paths>
</create_maint_traveler>
Here is how I am querying the values:
XDocument config = XDocument.Load(XML);
foreach (XElement node in config.Root.Elements("Paths"))
{
if (node.Name == "outputPath") outputPath = node.Value;
if (node.Name == "outputPath_today") outputPath = node.Value;
if (node.Name == "log") outputPath = node.Value;
}
When I output to a file, i find that the returned value is
D:\Intercim\DNC_Share\itcm\DataInput\MCDHeaderDrop\D:\Intercim\DNC_Share\itcm\DataInput\Today\D:\Intercim\DNC_Share\itcm\Log\CreateMaintLog.log
Or there will be nothing returned. I had the values in the XML file outside of the tags before which returned the one long value. I am confused about how to return the outputPath, outputPath_today and log values seperatly. Any help is appreciated.
Try:
You will get values of
outputPath,outputPath_todayandloginto anIEnumerableof anonymous objects. These objects each will have propertyoutputPath,outputPath_todayandlogwith values populated from XML.