Sgt-Peppa
May 23rd, 2003, 03:43 AM
Ok, i am pretty new to C# and xml. I have a project where I need to read an XML File and get some Values
first of all heres my xml Structure:
<doctypes>
<type>
<name>one</name>
<regexpression>testexp</regexpression>
<containsbin>no</containsbin>
</type>
<type>
<name>two</name>
<regexpression>onemore</regexpression>
<containsbin>no</containsbin>
</type>
</doctypes>
Now what I do is read in my xml doc, run through all nodes and compare the Values to a "Flatfile". Once I found a regexpression in the flatfile I want to write the name of it to a variable. Heres what I do up till now:
foreach(XmlNode n2 in docElement.ChildNodes) // for every childnode in doc_types
{
if(n2.Name =="type") // if childnode is called type then
{
foreach(XmlNode n3 in n2.ChildNodes) // read all the attributes of that type
{
//get the regexp and look in the doc if its there
if(n3.Name == "regexpression")
{
string tmp = n3.InnerText;
if(rest.IndexOf(tmp) !=-1)
{
//get the node before that node and write the inner text to header
//break the first for each
}
}
}
}
}
So heres my question: Once I found the regular Expression in my Flatfile I want to get the Value of the node <name> wich is one node before the <regexpression> node. How can I select the that node without running through all my nodes again?
Is that clear? Hope to hear from you guys,
Thanx in advance Stephan
first of all heres my xml Structure:
<doctypes>
<type>
<name>one</name>
<regexpression>testexp</regexpression>
<containsbin>no</containsbin>
</type>
<type>
<name>two</name>
<regexpression>onemore</regexpression>
<containsbin>no</containsbin>
</type>
</doctypes>
Now what I do is read in my xml doc, run through all nodes and compare the Values to a "Flatfile". Once I found a regexpression in the flatfile I want to write the name of it to a variable. Heres what I do up till now:
foreach(XmlNode n2 in docElement.ChildNodes) // for every childnode in doc_types
{
if(n2.Name =="type") // if childnode is called type then
{
foreach(XmlNode n3 in n2.ChildNodes) // read all the attributes of that type
{
//get the regexp and look in the doc if its there
if(n3.Name == "regexpression")
{
string tmp = n3.InnerText;
if(rest.IndexOf(tmp) !=-1)
{
//get the node before that node and write the inner text to header
//break the first for each
}
}
}
}
}
So heres my question: Once I found the regular Expression in my Flatfile I want to get the Value of the node <name> wich is one node before the <regexpression> node. How can I select the that node without running through all my nodes again?
Is that clear? Hope to hear from you guys,
Thanx in advance Stephan