Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

xml listing

using c#, is it possible to find all
assume i have xml file with over 1000 nodes below. I want to get the list of attitrbute called ID.
but I won't know where is the root. like tests or test.

I basically just want to loop xml to find all of the ID name, and then find t he element name.
once i get element name, then i want to fill in the value <ans>got it</ans>


and i
<tests>
<test id="id_name1">
   <ans id=id_ans1"></ans>
</test>
</test>
<test id="id_name2">
   <ans id=id_ans2"></ans></test>
</test>


</tests>
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

you can do something like below

XMLdocument to read the entire document in one shot and search that for your tags.

using System.Xml;
 XmlDocument document = new XmlDocument();
            document.Load("C:\\Pawan\\pawan2.xml");

            foreach (XmlNode node in document.GetElementsByTagName("test"))
            {
                foreach (XmlNode node1 in document.GetElementsByTagName("ans"))
                {
                    
                }
            }

Open in new window


your xml

<tests>
	<test id="id_name1">
	   <ans id="id_ans1"></ans>
	</test>	
	<test id="id_name2">
	   <ans id="id_ans2"></ans>
	</test>
</tests>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The solution completely answers the question.