Basic Xml Questions
Basic Xml Questions
Basic Xml Questions
Basic Xml Questions
Basic Xml Questions
Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions
Basic Xml Questions Basic Xml Questions
Basic Xml Questions
Go Back  Xtreme Visual Basic Talk > > > Basic Xml Questions


Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2013, 03:42 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default Basic Xml Questions


I have some questions about XmlWriter object. I've used it like this...

Code:
    writer.WriteStartDocument()
                writer.WriteStartElement("project") ' Root.

                '' Write document content

                writer.WriteStartElement("book")
                writer.WriteElementString("title", projectName)
                writer.WriteElementString("chapters", projectChapters)
                writer.WriteEndElement()


                ' End document.
                writer.WriteEndElement()
                writer.WriteEndDocument()
This creates a very simple Xml file, but I was also interested in creating a document with blank senctions for later saving, but if I put empty strings in I get a document like this

<project>
<book/>
<chapters/>
</project>

It doesn't look like I could insert values in there later...

also I'm going to need to do some kind of complex saving cuz I'll need to save values for character attributes that people make, I need project specific information saved, notes, and other stuff that will be saved from various objects from different places... What's the best method to do this?

The kind of xml file I was looking for would be

<project>
<file>
<filename></filename>
<path></path>
<chapters></chapters>
<title></title>
</file>
<characters>
<character>a list of character data</character>
</characters>
</project>

and everything else I would need in there.... If I could make a blank tampate xml file an update it through the software it would be easier, but with the way it makes empty tags I'm not sure this will work from the beginning stage of making the file.
Reply With Quote
  #2  
Old 01-01-2014, 09:41 AM
PlausiblyDamp's Avatar
PlausiblyDampBasic Xml Questions PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

In XML the format
Code:
<filename />
is just a shorthand for
Code:
<filename></filename>
it is generally preferred as it produces smaller XML output.

Are you planning on producing these templates and then hand editing them later or will you be using some form of provided XML support (XMLReader / XMLWrite, DOM, XLinQ) to modify the files later?

If you are using a provided mechanism then this should be taken care of for you, if you are hand editing the file then you can always change the format by hand - however if you are planning on hand editing the file you need to be careful in case you produce non-valid XML.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 01-01-2014, 03:53 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

I'll be editing the files pragmatically every time. I'm looking for the best possibly way to make a save option for my program. I'll be saving things from different forms too.

At first a create/open project dialogue will open. When they create a new document I was going to save a template XML file in My Documents/project folder and then when they saved file it would save to it.

Just not sure what the best way to go about saving is. This method will work?

Just curious.

When a document is like this?

<characters>
<name />
</characters>

What happens when a character name is saved in the blank place? Will it overwrite the document and output something like below.

<characters>
<name>Billy</name>
<name>Sam</name>
<name>Jake</name>
</characters>

Not sure what object I'd use from your list, I'd have to explore the, but I'll need one capable of easily inserting elements between root tags... For this bit of code I'm using XmlWriter.

Last edited by JeremyBenson11; 01-01-2014 at 04:02 PM.
Reply With Quote
  #4  
Old 01-01-2014, 04:55 PM
PlausiblyDamp's Avatar
PlausiblyDampBasic Xml Questions PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you are using one of the methods I mentioned then it would just create a document with the full format when you save it.

XMLWriter will do the job but XMLReader and XMLWriter can be a lot of work and lots of code when manipulating documents.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 01-06-2014, 08:20 AM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

Thanks for the reply. Is there a better way to do what I'm trying to do? Xml was the best I could come up with. I know most people would probably make a custom file of some kind, but I'm more interested in the easy way, lol...

I would like to use XML and create the file with data and be able to add data in the middle, but if it's a mess would be open to other options...

Thanks for taking the time.
Reply With Quote
  #6  
Old 01-06-2014, 08:21 AM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

Thanks for the reply. Is there a better way to do what I'm trying to do? Xml was the best I could come up with. I know most people would probably make a custom file of some kind, but I'm more interested in the easy way, lol...

I would like to use XML and create the file with data and be able to add data in the middle, but if it's a mess would be open to other options...

Thanks for taking the time.
Reply With Quote
  #7  
Old 01-07-2014, 11:20 AM
PlausiblyDamp's Avatar
PlausiblyDampBasic Xml Questions PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

There is nothing wrong with using XML, it can be a lot simpler than creating a custom file format and there are plenty of tools and libraries for working with it.

When it comes to being able to add extra data XML should be fine, it is just a matter of making sure the XML is correctly structured. If it is then any of the programming method mentioned above should work fine.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #8  
Old 01-11-2014, 07:57 AM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

Thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Basic Xml Questions
Basic Xml Questions
Basic Xml Questions Basic Xml Questions
Basic Xml Questions
Basic Xml Questions
Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions Basic Xml Questions
Basic Xml Questions
Basic Xml Questions
 
Basic Xml Questions
Basic Xml Questions
 
-->