Hello Everyone,
I have a problem statement where I want to retrieve the child nodes of the Particular ID
using Linq to XML I am able to get the whole node data along with the other data, how can I extract the child node from Environment.
Here's my XML file structure :
<ProjectEnvironments>
<ProjectEnvironment>
<ProjectId>22</ProjectId>
<ProjectName>Proj22</ProjectName>
<GroupName>Group</GroupName>
<ProjectApIUrl>http:
<ProjectUrl>http:
<Environments>
<Environment>
<EnvId>22</EnvId>
<EnvName>Proj22</EnvName>
</Environment>
<Environment>
<EnvId>33</EnvId>
<EnvName>Proj33</EnvName>
</Environment>
</Environments>
</ProjectEnvironment>
</ProjectEnvironments>
using the below code I am able to get the whole XML data based on the ProjectId, how can I get the data of Environments i.e. all EnvId and EnvName for the same node of ProjectId ?
XDocument _XDocument = XDocument.Load(@"C:\test.xml");
var items = from item in _XDocument.Elements("ProjectEnvironments").Elements("ProjectEnvironment")
where item != null && (item.Element("ProjectId").Value == projectId)
select item;
to get the Environments I tried the below code which is giving object reference error
var Envs = from itemz in _XDocument.Descendants("ProjectEnvironments").Descendants("ProjectEnvironment").Descendants("Environments").Descendants("Environment")
where item != null && (item.Element("EnvId").Value == _environments[0].EnvId)
select item;
Could anyone help me in getting this solved?
Thanks in Advance
What I have tried:
Here's my XML file structure :
<pre>
<ProjectEnvironments>
<ProjectEnvironment>
<ProjectId>22</ProjectId>
<ProjectName>Proj22</ProjectName>
<GroupName>Group</GroupName>
<ProjectApIUrl>http://localhost.dell.com/PremierToolsUX#/Gvt/API</ProjectApIUrl>
<ProjectUrl>http://localhost.dell.com/PremierToolsUX#/Gvt</ProjectUrl>
<Environments>
<Environment>
<EnvId>22</EnvId>
<EnvName>Proj22</EnvName>
</Environment>
<Environment>
<EnvId>33</EnvId>
<EnvName>Proj33</EnvName>
</Environment>
</Environments>
</ProjectEnvironment>
</ProjectEnvironments>
using the below code I am able to get the whole XML data based on the ProjectId, how can I get the data of Environments i.e. all EnvId and EnvName for the same node of ProjectId ?
XDocument _XDocument = XDocument.Load(@"C:\test.xml");
var items = from item in _XDocument.Elements("ProjectEnvironments").Elements("ProjectEnvironment")
where item != null && (item.Element("ProjectId").Value == projectId)
select item;
to get the Environments I tried the below code which is giving object reference error
var Envs = from itemz in _XDocument.Descendants("ProjectEnvironments").Descendants("ProjectEnvironment").Descendants("Environments").Descendants("Environment")
where item != null && (item.Element("EnvId").Value == _environments[0].EnvId)
select item;
Could anyone help me in getting this solved?