Working on Learning XML and using XML with c#

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Hi, I am trying to make a C# program that can read and write to a xml file.

Basically, I have a xml file called items. And it all items have 4 things to it. like Name,HP,MP,Discretio.

I can read a xml file, but i cant figure out how many Items i have. In other words in C# if i say read though the file, that i wrote by hand, and there are 4 Items. I can do that. But i am unsure how to say read throw all.

I am having a very hard time figuring out how to make it write to the XML file. I want to be able to first read all the data from the xml file, put it into in array, of the size of items in the xml file. But then latter, save the xml file, or make a new one, that replaces the old one with more or less xml data.

I dont fully understand nodes, and child's, ect. But i have a very small understanding.


Any Suggestions for me?
 

UndeadDragon

Super Moderator
Reaction score
447
I made a write line class in C#, which may be of use to you.

Code:
public void WriteLine(string name, string type, string attribute)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlPath);
            XmlElement Name = doc.CreateElement(name);
            Name.InnerText = attribute;
            XmlAttribute Type = doc.CreateAttribute("type");
            Type.Value = type;
            Name.SetAttributeNode(Type);
            doc.DocumentElement.InsertAfter(Name, doc.DocumentElement.LastChild);
            doc.Save(xmlPath);
        }

I also have ReadLine, RemoveLine and ReplaceLine if you want them.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Alright Thanks, Give me a bit of time to mess around with this.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top