all groups > dotnet xml > february 2005 >
You're in the

dotnet xml

group:

problem with WriteXml method


problem with WriteXml method Dixie Guo
2/24/2005 12:06:17 PM
dotnet xml:

Hi,

I used WriteXml() to write my data from DataSet to the file. The output
in the file is fine. However, there is one problem with my Column names
in the table. If my column name has more than two words seperated with
space, the output use "_x0020_" to connect those words.
For example, if I have column names, such as "Inbound Vehicle", "Arrived
At Holding", those names would be written as
"Inbound_x0020_Vehicle","Arrived_x0020_At_x0020_Holding". Anyone idea to
solve this problem is greatly appreciated.


*** Sent via Developersdex http://www.developersdex.com ***
Re: problem with WriteXml method Derek Harmon
2/24/2005 9:18:40 PM
[quoted text, click to view]

This is normal behavior, WriteXml( ) ensures that characters that may be legal
in a SQL column name but illegal in an XML non-colonized name (NCNAME)
are 'escaped' into something that XML will accept.

The code point (char) at hex 20 is ' ' (space).

The transformation is two-way, so that ReadXml( ) can similarly convert these
back into the SQL column names [Inbound Vehicle] and [Arrived At Holding].

[quoted text, click to view]

I suppose if you don't like how .NET solved the issue, you can always subclass
XmlTextWriter and wrap it around the output stream, before passing it to Write-
Xml( ). This way your XmlTextWriter subclass can intercept calls to write an
attribute or element name, and substitute your own solution. Just make sure that
it's reversible and you create a complementary XmlTextReader if you ever want
to reload that XML content back into the DataSet.


Derek Harmon

Re: problem with WriteXml method Dixie Guo
2/25/2005 5:54:19 AM
Derek,

Thank you very much. I will try your idea. Have a good day!

*** Sent via Developersdex http://www.developersdex.com ***
AddThis Social Bookmark Button