0

Well I'm new to the C# programming and i need a little help, i tried to find the answer to this question, but not find what i wanted for. Maybe i did bad search, so sorry.

I have this type of xml file:

<ROW>
<ID>1256464</ID>
<TEST>
<PROJECT1>
<PROJECT1_ID>984461</PROJECT1_ID>
</PROJECT1>
<PROJECT2>
<PROJECT2_ID>614115</PROJECT2_ID>
</PROJECT2>
<PROJECT3>
<PROJECT3_ID>134998</PROJECT3_ID>
</PROJECT3>
</TEST>
<RESULTS>
<GRADE1>
<GRADE1_ID>6561616</GRADE1_ID>
</GRADE1>
<GRADE2>
<GRADE2_ID>6687979</GRADE2_ID>
</GRADE2>
<GRADE3>
<GRADE3_ID>13156665</GRADE3_ID>
</GRADE3>
</RESULTS>
</ROW>

There are many rows, the file is very large. So i supposed to use XmlTextReader function. At least i wrote a small code:

    XmlTextReader reader = new XmlTextReader("items.xml");
    while (reader.Read())
    {
    XmlNodeType nodeType = reader.NodeType;
    if (nodeType == XmlNodeType.Element)
    {
    if (reader.NodeType == "ID")
    {
    //this node value i get to the console but others not, if them are in depth
    Console.WriteLine(reader.ReadString());
    }
    //tried to do this stuff i know it's wrong
    //but i cant get the value of this elment how should i loop through
    //and of course i need to reach grade1_id fields and loop through
    if (reader.NodeType == "PROJECT2_ID")
    {
    Console.WriteLine(reader.ReadString());
    }
    }
    }
  • that XML looks wrong - I believe `...` would be the way to go, otherwhise it is plainly impossible to write a xml parser with xmltextreader (and dom too...) – Najzero Feb 12 '13 at 14:35
  • you talking about attributes to exact node name yes ? if so it can't be done, because i get the file large and the type of file is looking like i showed. So what type of namespaces should i use ? – SeeSharpWithGoggles Feb 12 '13 at 14:41
  • I think he means the XML should Look like: ... ... or are you saying you simply get the file in this format and must go on with it? – The-First-Tiger Feb 12 '13 at 17:50
  • Yes i get the data in this format and i need to loop it through. As far as i read, that attributes to the node would be easier task, but in my case i got in this format only. – SeeSharpWithGoggles Feb 12 '13 at 20:34

1 Answers1

0

I would like to point out that the XML you wrote is invalid. The tag <GRADE_something_ID> doesn't actually have a closing tag. (ie. the second tag is missing the /-thingy)

I assume thats a typo in the example? Otherwise you may be in for a world of pain parsing this XML-file.

Faranx
  • 1
  • 3