Charles Baldo
asked on
Need to read XML child values from root
Hi I am looking to read child xml values from a root without having to reselect each value. I wooul like to get the element name and value.
For instance with the XML and Code attached I would like to end up with
UserName: BobbyBrady
ImportFolder: C:\ImportImages
UserWatchFolder: C:\temp\INFO\BobbyBrady
DATAFolder: C:\temp\INFO\DATA
Sharee: CindyBrady
ShareName: CindyBrady
ShareText: CindyBradyShare Text4
I have been doing a .Select for each element to get the value nav.Select("/TestConfig/Te sts/Test[@ TestName=' Test4']/Us erName");
Any help is appreciated
For instance with the XML and Code attached I would like to end up with
UserName: BobbyBrady
ImportFolder: C:\ImportImages
UserWatchFolder: C:\temp\INFO\BobbyBrady
DATAFolder: C:\temp\INFO\DATA
Sharee: CindyBrady
ShareName: CindyBrady
ShareText: CindyBradyShare Text4
I have been doing a .Select for each element to get the value nav.Select("/TestConfig/Te
Any help is appreciated
private static void getAllUsers(String sFile)
{
XmlDocument doc = new XmlDocument();
doc.Load(sFile);
XmlNode oNode = doc.DocumentElement;
XmlNodeList oNodeList;
oNodeList = oNode.SelectNodes("/TestConfig/Tests/Test[@TestName='Test4']");
<?xml version="1.0" encoding="utf-8"?>
<TestConfig>
<Tests>
<Test TestName="Test1">
<UserName>GregBrady</UserName>
<ImportFolder>C:\ImportImages</ImportFolder>
<UserWatchFolder>C:\temp\INFO\GregBrady</UserWatchFolder>
</Test>
<Test TestName="Test2">
<UserName>MarciaBrady</UserName>
<ImportFolder>C:\ImportImages</ImportFolder>
<UserWatchFolder>C:\temp\INFO\MarciaBrady</UserWatchFolder>
<DATAFolder></DATAFolder>
<Sharee></Sharee>
<ShareName></ShareName>
<ShareText></ShareText>
</Test>
<Test TestName="Test3">
<UserName>JanBrady</UserName>
<ImportFolder>C:\ImportImages</ImportFolder>
<UserWatchFolder>C:\temp\INFO\JanBrady</UserWatchFolder>
<DATAFolder>C:\temp\INFO\DATA</DATAFolder>
<Sharee>PeterBrady</Sharee>
<ShareName>PeterBradyShare</ShareName>
<ShareText>PeterBradyShare Text3</ShareText>
</Test>
<Test TestName="Test4">
<UserName>BobbyBrady</UserName>
<ImportFolder>C:\ImportImages</ImportFolder>
<UserWatchFolder>C:\temp\INFO\BobbyBrady</UserWatchFolder>
<DATAFolder>C:\temp\INFO\DATA</DATAFolder>
<Sharee>CindyBrady</Sharee>
<ShareName>CindyBrady</ShareName>
<ShareText>CindyBradyShare Text4</ShareText>
</Test>
</Tests>
</TestConfig>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Thats not bad and an improvement to what I have, what I am hoping fro is to be able to iterate through the child elements without knowing what they are.
I will accept this and put a more specific post up
Thats not bad and an improvement to what I have, what I am hoping fro is to be able to iterate through the child elements without knowing what they are.
I will accept this and put a more specific post up
ASKER
Yes that is what I want. Thanks a ton
Open in new window