473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem using xml writer

Hi
I want to create following xml document using xmlwriter

<?xml version="1.0" ?>
- <epps>
- <remit_trn type="technical">
<remit_date_dtm dtm = "201" >test</remit_date_dtm>
<rmt_payee_n1>test</rmt_payee_n1>
<rmt_payee_n1>test</rmt_payee_n1>
<rmt_ref>test</rmt_ref>
</remit_trn>
</epps>

I wrote the code to do the same but when I run the code
I am getting following exception on executing the
following line
xmlw.WriteAttributeString("dtm01" , "201");

Token StartAttribute in state Content would result in an
invalid XML document
I dont know why its not allowing me to add attribute to
remit_date_dtm element above. I am herebelow giving the
complete code which I wrote. I would really appreciate if
someone can helm me with this problem

Thanks
Vikas
CXmlWriter lclsXmlWriter = new CXmlWriter();

string filename = "c:\\clevxml.xml";
XmlTextWriter xmlw = new XmlTextWriter(filename,null);
xmlw.Formatting=Formatting.Indented;
xmlw.WriteStartDocument();
xmlw.WriteStartElement("epps");
xmlw.WriteStartElement("remit_trn");
xmlw.WriteAttributeString("type", "technical");
xmlw.WriteElementString("remit_date_dtm" ,"test");
xmlw.WriteAttributeString("dtm01" , "201");
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_ref","test");
xmlw.WriteEndElement();
xmlw.WriteEndElement();
Nov 11 '05 #1
4 8129
Did you use the XMLWriter class in .NET framework or a component from third
party?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 11 '05 #2
vikas wrote:
string filename = "c:\\clevxml.xml";
XmlTextWriter xmlw = new XmlTextWriter(filename,null);
xmlw.Formatting=Formatting.Indented;
xmlw.WriteStartDocument();
xmlw.WriteStartElement("epps");
xmlw.WriteStartElement("remit_trn");
xmlw.WriteAttributeString("type", "technical");
xmlw.WriteElementString("remit_date_dtm" ,"test");
xmlw.WriteAttributeString("dtm01" , "201");


Here is your mistake. You cannot write attribute when element content has been
written already. It should be

xmlw.WriteStartElement("remit_date_dtm");
xmlw.WriteAttributeString("dtm01" , "201");
xmlw.WriteString("test");
xmlw.WriteEndElement();
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_ref","test");
xmlw.WriteEndElement();
xmlw.WriteEndElement();

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
vikas wrote:
string filename = "c:\\clevxml.xml";
XmlTextWriter xmlw = new XmlTextWriter(filename,null);
xmlw.Formatting=Formatting.Indented;
xmlw.WriteStartDocument();
xmlw.WriteStartElement("epps");
xmlw.WriteStartElement("remit_trn");
xmlw.WriteAttributeString("type", "technical");
xmlw.WriteElementString("remit_date_dtm" ,"test");
xmlw.WriteAttributeString("dtm01" , "201");


Here is your mistake. You cannot write attribute when element content has been
written already. It should be

xmlw.WriteStartElement("remit_date_dtm");
xmlw.WriteAttributeString("dtm01" , "201");
xmlw.WriteString("test");
xmlw.WriteEndElement();
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_ref","test");
xmlw.WriteEndElement();
xmlw.WriteEndElement();

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4
Hi Oleg,
Thanks a lot for your help.

Thanks
vikas
-----Original Message-----
vikas wrote:
string filename = "c:\\clevxml.xml";
XmlTextWriter xmlw = new XmlTextWriter(filename,null);
xmlw.Formatting=Formatting.Indented;
xmlw.WriteStartDocument();
xmlw.WriteStartElement("epps");
xmlw.WriteStartElement("remit_trn");
xmlw.WriteAttributeString("type", "technical");
xmlw.WriteElementString("remit_date_dtm" ,"test");
xmlw.WriteAttributeString("dtm01" , "201");
Here is your mistake. You cannot write attribute when

element content has beenwritten already. It should be

xmlw.WriteStartElement("remit_date_dtm");
xmlw.WriteAttributeString("dtm01" , "201");
xmlw.WriteString("test");
xmlw.WriteEndElement();
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_payee_n1" ,"test");
xmlw.WriteElementString("rmt_ref","test");
xmlw.WriteEndElement();
xmlw.WriteEndElement();

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Olav Tollefsen | last post by:
I'm using the following code to create an Xml document to be saved by the browser (IE): MemoryStream stream = new MemoryStream(); OrderManager.ExportToXml(stream); // Creates...
4
by: Axel Dahmen | last post by:
Hi, I've got the same problem as described below. No answer found yet. Can someone please help? (I'm using .NET 1.0 on my development machine and 1.1 on my webserver. Like Susanna, I only get...
1
by: José Joye | last post by:
Hello, I'm playing around with dynamically loading user controls ...and having problems I created a really simple userControl (in fact contains a plain text box) and placed it into the...
1
by: Bart Schelkens | last post by:
Hi, i have this website (www.polytools.be) it works fine when i'm viewing it with Internet Explorer. When i'm trying to view it with mozilla, i get the following error : Server Error in '/'...
1
by: I am Sam | last post by:
using System; using System.Drawing; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.ComponentModel;...
0
by: ACC | last post by:
Hi! I'm new around xml and xslt... I'm trying to write a dataset to a CSV file. I'm doing like this: I'm creating a Stylesheet: writer is a XmlTextWriter. (...) // xsl-template...
2
by: corley | last post by:
Hello world, I am having a problem with the decimal symbol. The result of writing a floating-point-number to an xml document (using libxml2 from xmlsoft.org) is <number>10,1234</number> ...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
0
by: iprogrammer | last post by:
i have a problem when i try to run my windows service ..which is "Error 1053: The service did not respond to the start or control request in a timely fashion" >after this i cannot anything with...
2
by: OllieHag | last post by:
Hi, can anyone help me out with this problem? In the code posted below, why does my count of Data objects only return 1, not 3. If I comment out the IXmlSerializable inheritance in the Data class,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.