XML files in C#

Started by
7 comments, last by Ashandir 20 years, 5 months ago
I am making a RPG text game with C#. I have an xml file that saves the players name password and the class they choose. I want to create a child node in the XML file so that I can make an item collection to keep track of the items that the player has. But I cant figure out how to create a child to a player attribute in an XML file. Can anyone explain the syntax for that to me. Thank You
Advertisement
Please answer I got to go soon and I need an answer!
<root>   <child of root>      <child of child of root>      </child of child of root>   </child of root></root>


See any patterns?

[edited by - CodeMunkie on November 17, 2003 4:20:54 PM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Yeah I see how I can write it directly in the XML but how do I make C# create a child and make an attribute for that child?
What are you using to generate the XML file in the first place? I usually use the built-in XML schema editor to create the schema and then have it autogenerate a datagrid. The nice thing about the datagrid is that it will conform to your schema and it has built in functions to read and write itself to/from XML. You can also .addRow, .addColumn, etc (it has quite a few functions for modifying) and you can visually edit the control if you want to easily do data entry into it.
They may or may not help, but you are not providing any info about what you are doing, so how is anyone suppose to help?
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
I have a parent Node that has attributes of password player name and class. I am then going to create an exit collection. And I want to store the info in an XML. When you start the program if you dont have a character you then create one. So it adds to the XML the base which is name password and the class you choose. I want it at this time to make a child to this that contains your inventory. I can create the first lvl but I cant figure out the syntax in C# to add a child attribute to it. this is my file


-











I want to make a child that would look like

-





But I do not know the syntax to do this. Can anyone help me do this with C#.
You'll have to put your XML in source tags for it to show up.
quote:but I cant figure out the syntax in C# to add a child attribute to it

Again, how are you handling the XML in your app? I mean, what control, library, namespace are you using that actually creates the XML tree and does the file I/O?
And what is an "exit collection"? I'm not familiar with that term.

[edited by - CodeMunkie on November 17, 2003 4:56:23 PM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Use the XmlDocument to create the attribute.

XmlDocument doc;//...XmlAttribute attribute = doc.CreateAttribute( "attributename" );attribute.Value = "value";someNode.Attributes.SetNamedItem( attribute ); 

Creation of other types of nodes work the same way.

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
If you are using the XMLDom then look up createElement on MSDN. You will need one of these before you can create an attribute.

This topic is closed to new replies.

Advertisement