Archived

This topic is now archived and is closed to further replies.

Ashandir

XML files in C#

Recommended Posts

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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#.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you are using the XMLDom then look up createElement on MSDN. You will need one of these before you can create an attribute.

Share this post


Link to post
Share on other sites