473,407 Members | 2,314 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,407 software developers and data experts.

Losing space character value when writing attribute

Hi,

Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily
using the WriteAttributeString method of XmlWriter object, but have run into
a problem when trying to output a space character as the value of an
attribute.

Prototype of the method I am using is XmlWriter.WriteAttributeString
(String, String) in the following fashion:

xmlTextWriter.WriteStartElement("Rule");
xmlTextWriter.WriteAttributeString("Separator", " ");
xmlTextWriter.WriteEndElement();

Which results in the following XML:

<Rule Separator="" />

I've looked into xmlTextWriter.WriteWhiteSpace(string) but this outputs
directly into the text writer object, which doesn't help when trying to
write a value for an attribute of an element. I've also checked the other
properties to see if there is a "preserve white space" setting, which I
can't see.

Can anyone throw any light on a possible solution? Can I encode the space
differently to make sure it is kept in the output XML when using
WriteAttributeString or do I have to use a different method (which one?) or
a completely different object for outputting the XML?

Regards,

- Paul.


May 17 '06 #1
4 3238
I cannot reproduce the problem, provide sample code please.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Paul Hadfield wrote:
Hi,

Wonder if anyone can help me on this, In DotNet2.0 I've been quite happily
using the WriteAttributeString method of XmlWriter object, but have run into
a problem when trying to output a space character as the value of an
attribute.

Prototype of the method I am using is XmlWriter.WriteAttributeString
(String, String) in the following fashion:

xmlTextWriter.WriteStartElement("Rule");
xmlTextWriter.WriteAttributeString("Separator", " ");
xmlTextWriter.WriteEndElement();

Which results in the following XML:

<Rule Separator="" />

I've looked into xmlTextWriter.WriteWhiteSpace(string) but this outputs
directly into the text writer object, which doesn't help when trying to
write a value for an attribute of an element. I've also checked the other
properties to see if there is a "preserve white space" setting, which I
can't see.

Can anyone throw any light on a possible solution? Can I encode the space
differently to make sure it is kept in the output XML when using
WriteAttributeString or do I have to use a different method (which one?) or
a completely different object for outputting the XML?

Regards,

- Paul.

May 17 '06 #2
Example code, just the relevant bits from the more detailed document is:

string fileName = "Test.xml";
string separator = " ";
XmlTextWriter xmlTextWriter = new XmlTextWriter(new StreamWriter(fileName,
false, System.Text.Encoding.ASCII));

xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.WriteStartDocument();

xmlTextWriter.WriteStartElement("TransformationRul e");

xmlTextWriter.WriteAttributeString("Delimiter", separator);

xmlTextWriter.WriteEndElement();

xmlTextWriter.WriteEndElement();

results in the attribute Delimiter being written out as

<TransformationRule Delimiter="" /> rather than <TransformationRule
Delimiter=" " />

Please note that the only issue is that the space is lost in the attribute.
"Oleg Tkachenko [MVP]" <so**@body.com> wrote in message
news:eV**************@TK2MSFTNGP02.phx.gbl...
I cannot reproduce the problem, provide sample code please.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Paul Hadfield wrote:
Hi,

Wonder if anyone can help me on this, In DotNet2.0 I've been quite
happily using the WriteAttributeString method of XmlWriter object, but
have run into a problem when trying to output a space character as the
value of an attribute.

Prototype of the method I am using is XmlWriter.WriteAttributeString
(String, String) in the following fashion:

xmlTextWriter.WriteStartElement("Rule");
xmlTextWriter.WriteAttributeString("Separator", " ");
xmlTextWriter.WriteEndElement();

Which results in the following XML:

<Rule Separator="" />

I've looked into xmlTextWriter.WriteWhiteSpace(string) but this outputs
directly into the text writer object, which doesn't help when trying to
write a value for an attribute of an element. I've also checked the
other properties to see if there is a "preserve white space" setting,
which I can't see.

Can anyone throw any light on a possible solution? Can I encode the
space differently to make sure it is kept in the output XML when using
WriteAttributeString or do I have to use a different method (which one?)
or a completely different object for outputting the XML?

Regards,

- Paul.


May 17 '06 #3
Ok, I get it. You must be viewing resulting XML in Internet Explorer and
IE shows empty attributes this way. Take a look into sources.
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
May 17 '06 #4
Duh!, what a school boy error! Thanks for bearing with me, sure enough
source is fine!

Cheers,

- Paul.

"Oleg Tkachenko [MVP]" <so**@body.com> wrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
Ok, I get it. You must be viewing resulting XML in Internet Explorer and
IE shows empty attributes this way. Take a look into sources.
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

May 17 '06 #5

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

Similar topics

0
by: Phillip Farber | last post by:
Hello, I'm posting here with a somewhat technical question in the hope of finding someone with experience coding C++ against the SP_API in OpenSP 1.5. I have an app that uses the SP_API to...
0
by: Ray Tayek | last post by:
hi, trying to convert some csv files into xsml and pulling a few hairs out :(. using the files below. a java program will parse the csv and take care of strange names and notes that line breaks in...
1
by: Mark247 | last post by:
Hi, When transforming an XSLT to HTML I get a very annnoying white spac gap of about 2px under each image. This is particularly annoying as am creating a vertical navigation menu made up of images...
28
by: Andreas Prilop | last post by:
Jukka reports on http://www.cs.tut.fi/~jkorpela/chars/spaces.html that Internet Explorer 6 fails on the "zero width space" U+200B ​ Is this observation still valid? For which versions of MS...
10
by: Angel | last post by:
I want to concat a space in an HTML Control's innerText property. here is a sample code Dim celCreate As New HtmlControls.HtmlTableCell() celCreate.innerText = " TEST" When the page is...
14
by: gooooglegroups | last post by:
I want to transform the following xml file ------------------------------------------------------------------------ <?xml version="1.0" encoding="ISO-8859-1"?> <a> <b attrib="if 3 2"> </b> ...
4
by: kollatjorva | last post by:
Hi all I'm trying to get a value from an xml node 'Publisher' use the value as a name of an .css class. This works fine until I get a value from the Publisher node with white space in it. I've...
3
by: kvnsmnsn | last post by:
I've written the following Javascript file that includes an input text field and an output text field, the latter of which is initialized to zero. Each time the user enters a number in the input...
5
by: Richard Maher | last post by:
Hi, Can someone please show me how to tell Firefox to preseve white-space when returning the selectList.option.value attribute? I have change the style so that the white-space is preserved on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.