473,322 Members | 1,755 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,322 software developers and data experts.

Question regarding WriteElementString

Hello,

I'm using XMLTextWriter to create a XML file from a database table.

I use WriteElementString to create elements. I'm having two issues:

1. When a data field is null, I get an error.

XMLTextWriter.WriteElementString("Name", dr("Name"))

2. When a data field is a date/timestamp field, I get an error.

Any help will be appreciated. Thanks.
Nov 14 '06 #1
3 2690
janus1114 wrote:
I'm using XMLTextWriter to create a XML file from a database table.

I use WriteElementString to create elements. I'm having two issues:

1. When a data field is null, I get an error.

XMLTextWriter.WriteElementString("Name", dr("Name"))
What is dr exactly? What do you want to happen when the field is empty,
write an empty element?

2. When a data field is a date/timestamp field, I get an error.
What error? Can you call ToString e.g.
writer.WriteElementString("date", dr("Date").ToString())
to avoid the error?

In .NET 2.0 there are also methods to write typed data e.g.
<http://home.arcor.de/martin.honnen/javascript/2006/11/test2006111402.html>
in .NET 1.x you might want to use XmlConvert.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 14 '06 #2
Hi there,

Thank you for the help.

When the field is empty, I still want to write an empty element like
<name></name>.

When I call ToString I get an empty element like this:

</name>

Without the first half <Name>

Please advise. Thanks!

What is dr exactly? What do you want to happen when the field is empty,
write an empty element?

Nov 14 '06 #3
Can you change dr to return ampty string instead on null for the empty field?

-Helena

"janus1114" wrote:
Hi there,

Thank you for the help.

When the field is empty, I still want to write an empty element like
<name></name>.

When I call ToString I get an empty element like this:

</name>

Without the first half <Name>

Please advise. Thanks!

What is dr exactly? What do you want to happen when the field is empty,
write an empty element?
Nov 15 '06 #4

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

Similar topics

3
by: Anders Borum | last post by:
Hello Jon, et all. I am working on a framework with context bound objects (models). The objects expose common functionality, such as the ability to get a serialized Xml representation of an...
1
by: Chris Fink | last post by:
I have a general question regarding this piece of code that I wrote. This works fine, however I am confused as to how I am able to pull the sb instance out at the end? When I create the...
2
by: Fred | last post by:
Hi I need to loop through the properties of an object and record the various values. I have some reflection code that does this nicely but any enumerated properties return the Text of the...
6
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is...
4
by: needin4mation | last post by:
Hi, string filename = "Directions2.xml"; XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("Directions2.xml")); XmlElement root = doc.DocumentElement; XmlNode oldLoc; oldLoc =...
13
by: jcrouse | last post by:
Here is some of my code Dim myXmlTextWriter As XmlTextWriter = New XmlTextWriter("C:\CPViewer\CPViewer.xml", System.Text.Encoding.Unicode myXmlTextWriter.Formatting =...
6
by: Jon | last post by:
All, I'm working in a fairly robust content management system for our company's websites, and have a question regarding the file and directory structure of the site. Currently, I'm populating...
2
by: fmancina | last post by:
Hi, I am employing the XmlTextWriter class to generate an XML document. Everything works fine, until I have to write an attribute to an element which contains a value. Examples below: //...
2
by: Randy | last post by:
I'm creating XML using the above. My problem is that if I have a string that is passed to WriteElementString such as WriteElementString("description", @"<!]>"); then, it outputs the XML as......
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.