JBudOne
Member
- Joined
- Jul 28, 2006
- Messages
- 6
Ok, so I want to write something into the xml file and then read it. Im a total n00b and so Im sure its something basic. But ive checked and messed around with it for, I guess 3 days now =( any help would be greatly appreciated.
The XML looks kind of like:
So there are no errors when building this, but it shows, 3 in Label1. Any ideas or suggestions are greatly appreciated. Thx.
C#:
public static string LoadXML(String TheParent, String TheChild)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"SP.xml");
System.Xml.XmlNode node = doc.DocumentElement;
string data = "";
{
if (node.LocalName == "XMLDoc")
{
node.SelectSingleNode(TheParent);
System.Collections.IEnumerator rootIter = node.GetEnumerator();
while (rootIter.MoveNext())
{
System.Xml.XmlNode currentNode = (System.Xml.XmlNode)rootIter.Current;
data = currentNode[TheChild].InnerText;
break;
}
}
}
return data;
}
public void WriteXML(String TheParent, String TheChild, String TheValue)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(@"SP.xml");
System.Xml.XmlNode node = doc.DocumentElement;
node.SelectSingleNode(TheParent);
System.Collections.IEnumerator rootIter = node.GetEnumerator();
while (rootIter.MoveNext())
{
System.Xml.XmlNode currentNode = (System.Xml.XmlNode)rootIter.Current;
currentNode[TheChild].SetAttribute(TheChild, TheValue);
break;
}
private void button1_Click(object sender, EventArgs e)
{
int TestMe = 15;
WriteXML("Main", "Subjects", TestMe.ToString());
Label1.Text = LoadXML("Main", "Subjects");
}
The XML looks kind of like:
Code:
<XMLDoc>
<Main>
<Subjects>3</Subjects>
<Groups>9</Groups>
<Qs>18></Qs>
</Main>
</XMLDoc>
So there are no errors when building this, but it shows, 3 in Label1. Any ideas or suggestions are greatly appreciated. Thx.
Last edited by a moderator: