Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2008, 10:06 AM
Authorized User
 
Join Date: Aug 2006
Location: delhi, delhi, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default Creating XML doc ; writing string(xml format) into

I have to write a string in XML Doc, which is having all nodes in it.

I have to create and save this XML doc also.

steps are:

*Create xml doc (to some location) (this writes: (?xml version="1.0" encoding="utf-8" ?>
*writing string into it. (it contains elements, attrib and values)
*closing document
*save it.

How to do this ?
please reply soon.
thanks
Reply With Quote
  #2 (permalink)  
Old May 27th, 2008, 10:11 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

a) We don't do people homework for them
b) You don't say what programming language you are using - if I told you how to do this in COBOL or Perl would that help?
c) Give it a try yourself, and if you get stuck and have a particular problem come back and we might be able to help.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old May 27th, 2008, 10:12 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well which programming language (e.g. C#, Java) and which framework/SDK (e.g. .NET 2.0 or .NET 3.5 or Java 1.5 or Java 1.6) do you want to use?

--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
  #4 (permalink)  
Old May 28th, 2008, 12:55 AM
Authorized User
 
Join Date: Aug 2006
Location: delhi, delhi, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default

I am using C# and .Net2.0.
Reply With Quote
  #5 (permalink)  
Old May 28th, 2008, 01:09 AM
Authorized User
 
Join Date: Aug 2006
Location: delhi, delhi, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to KamalRaturi Send a message via Yahoo to KamalRaturi
Default

Hi Sam Judson, Martin Honnen

The code I am using is:

XmlTextWriter xmlWRITER = new XmlTextWriter(Server.MapPath("~/common/xml/SegmentXML.xml"), null);
            xmlWRITER.Formatting = Formatting.Indented;
            xmlWRITER.Indentation = 4;
            xmlWRITER.WriteStartDocument();
            xmlWRITER.WriteString(Brand1.ToXml()); //ToXml returns XML-String
            xmlWRITER.WriteEndDocument();
            xmlWRITER.Close();


and the error is:
Token Content in state Prolog would result in an invalid XML document.

As result It creates Xml document but it is empty.
Reply With Quote
  #6 (permalink)  
Old May 28th, 2008, 05:51 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The usual approach with Xml(Text)Writer is to write element, attributes, text, comments and it constructs the XML for you.
If you want to write a string of XML and do not want to escape it then you need to use WriteRaw:
Code:
xmlWRITER.WriteRaw(Brand1.ToXml());
It is your responsibility then that you write well-formed markup.
See http://msdn.microsoft.com/en-us/libr....writeraw.aspx


--
  Martin Honnen
  Microsoft MVP - XML
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating word doc. thru .dot or XML document manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 2 March 1st, 2006 07:18 AM
Help making a doc using XML topshed XML 2 January 28th, 2006 08:05 PM
creating a structured xml from an unstructured xml geoffgeoffgeoff XSLT 0 August 10th, 2005 02:58 PM
How can I view an XML doc to HTML format jolo98 XML 3 July 23rd, 2004 01:02 AM
whole database to XML doc beyondforsaken VB How-To 4 June 11th, 2003 08:12 PM



All times are GMT -4. The time now is 04:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.