|
-
July 28th, 2006, 04:59 PM
#6
Re: Reading + Writing XML
Aright so I changed my code to match yours, and tried changing the WriteXML() to sorta match the LoadXML() method. Came out to:
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;
}
}
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;// Int32.Parse(LoadXML("Main", "Subjects")) + 1;
WriteXML("Main", "Subjects", TestMe.ToString());
QsStr.Text = LoadXML("Main", "Subjects");
}
...Same thing. The LoadXML() works fine, and i'm even checking the .xml itself, and it isn't changing. Theres no error but it won't write the file. I also checked the debug folder and there is no extra file in there that it may have written to. =( Any ideas or suggestions?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|