Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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 -/
  #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
  #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.
  #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.
  #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


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.