- Home /
how do I search for an atribute in a XML file?
Hello guys, I'm trying to seach for all the tags that have a expecific attribute, with no luck any help?
My XML file is something like this:
<questions>
<question id = "1" topic = "Science" language = "EN">
<ask>test</ask>
<answer1>test</answer1>
<answer2>test</answer2>
<answer3>test</answer3>
<answer4>test</answer4>
<rightOne>4</rightOne>
</question>
(...)
I only know how to get the information this way:
public void SetupQuestion(int identifier){
questions[identifier-1].TryGetValue("ask", out ask);
questions[identifier-1].TryGetValue("answer1", out answer1);
questions[identifier-1].TryGetValue("answer2", out answer2);
questions[identifier-1].TryGetValue("answer3", out answer3);
questions[identifier-1].TryGetValue("answer4", out answer4);
questions[identifier-1].TryGetValue("rightOne", out rightOne);
questions[identifier-1].TryGetValue("topic", out topic);
questions[identifier-1].TryGetValue("id", out id);
}
But how do I get all the questions by topic instead of by the order that they are placed in the document?
Thanks for your time!
Comment
Well, you could write a Python script using sgml. It let's you write really handy parser for X$$anonymous$$L. At least I suppose so :D
But if you want to stick with C# I would say you should get familiar with regular expressions.