i have a xml like following one.
<testing>
<node01 name="node01Name">
<node02s>
<node02 name="1">
<CustomProperties>
<CustomProperty Name="ASCII File Name" Value="index.txt" FilterID="0" />
<CustomProperty Name="ASCII Folder" Value="\\abc\cdf\aaaa" FilterID="0" />
<CustomProperty Name="Delimiter" Value="CommaQuote" FilterID="0" />
<CustomProperty Name="Duplicate Handling" Value="Replace if Dup" FilterID="0" />
<CustomProperty Name="EMAILATTDOC" Value="1" FilterID="0" />
<CustomProperty Name="EMAILATTINDEX" Value="0" FilterID="0" />
<CustomProperty Name="EMAILOUTBODY" FilterID="0" />
<CustomProperty Name="EMAILOUTCC" FilterID="0" />
</CustomProperties>
</node02>
<node02 name="2">
<CustomProperties>
<CustomProperty Name="ASCII File Name" Value="index.txt" FilterID="0" />
<CustomProperty Name="ASCII Folder" Value="\\abc\cdf\aaaa" FilterID="0" />
<CustomProperty Name="Delimiter" Value="CommaQuote" FilterID="0" />
<CustomProperty Name="Duplicate Handling" Value="Replace if Dup" FilterID="0" />
<CustomProperty Name="EMAILATTDOC" Value="1" FilterID="0" />
<CustomProperty Name="EMAILATTINDEX" Value="0" FilterID="0" />
<CustomProperty Name="EMAILOUTBODY" FilterID="0" />
<CustomProperty Name="EMAILOUTCC" FilterID="0" />
</CustomProperties>
</node02>
</node02s>
</node01>
</testing>
I need to get each CustomProperty under each node02. this is my code.
XDocument configparentXML = XDocument.Load("admin.xml");
string node = "node02";
var batchClasses = from batchClasse in configparentXML.Descendants(node)
select new ReadingXmlWithLinq
{
BatchClassName = batchClasse.Attribute("Name") != null ? batchClasse.Attribute("Name").Value : "",
};
foreach (var lv0 in batchClasses)
{
node = "CustomProperty";
var CustomProperties = from CustomProperty in configparentXML.Descendants(node)
select new ReadingXmlWithLinq
{
CustomPropertyName = documentClasse.Attribute("Name") != null ? documentClasse.Attribute("Name").Value : ""
};
}
But in hear its return all CustomPropery Values. How can i get CustomerPropery for a node02 ?
Thank you very much.
I’d approach this with XPath:
EDIT
To get all nodes under (say)
<node02 name="2">you could alter the path as follows:Here’s a page of XPath examples so you can see what’s possible.