Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<?xml version="1.0" encoding="utf-8"?>
<ExtractorData xmlns="urn:www.phas.com/services/2.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Level>
        <Name>TestA</Name>
        <ExtractionInfo>
            <Report ReportId="one" GroupId="B">
                <Name>ReportA</Name>
                <OutputLocationFormat>Test/folderA</OutputLocationFormat>
                <OutputFileType>PDF</OutputFileType>
                <ExecutionType>
                    <InstallSpecExecuteReportSaveOutput SpecFilePath="Specs\Target.xml">
                        <SearchPath>/content/folder[@name='{0}']/folder[@name='CRF Reports']</SearchPath>
                    </InstallSpecExecuteReportSaveOutput>
                </ExecutionType>
            </Report>
        </ExtractionInfo>
        <ExecutionType>
            <InstallSpecExecuteReportSaveOutput SpecFilePath="Specs\Target.xml">
                <SearchPath>/content/folder[@name='{0}']/folder[@name='CRF Reports']</SearchPath>
            </InstallSpecExecuteReportSaveOutput>
        </ExecutionType>
    </Level>
</ExtractorData>


I have used this code snipet -

XDocument xmlDoc = XDocument.Load("C:/abc.xml");

var levels = from levl in xmlDoc.Descendants()
where levl.Name.LocalName == "ExecutionType"
select levl;
Posted
Updated 6-Apr-15 2:33am
v4
Comments
CHill60 6-Apr-15 8:25am    
What code did you use?
AshokAgrawal 6-Apr-15 8:38am    
Hi Chill,
I have updated my question. Could you please tell me that how can i get the main child element under root element "Level". I don't want to read the same element under "Report" element. Actually i want to get them separately.


Thanks in advance.

1 solution

Your code is getting them all.

levels is of type "System.Linq.Enumerable+WhereEnumerableIterator`1[System.Xml.Linq.XElement]" so it contains a "list" of the matching nodes.

You can filter it further on the read
SQL
var levels = from levl in xmlDoc.Descendants()
                where (levl.Name.LocalName == "ExecutionType" && levl.Parent.Name == "Level")
                select levl;

or you can determine what the parent node is when you are using the data (which I guess is what you need as you said "I want to get them separately")
E.g.
C#
foreach (var l in levels)
{
    Console.WriteLine(l.Parent.Name);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900