472,145 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Xml and unicode values with &#x...

Hello!

I like to use the XmlTextWriter to write some SVG files.

But in some cases, I need the '&' as '&' and not as &.

Example: <glyph unicode="&#x4c;"/>

Some code-snippet:

XmlDocument ^ doc = gcnew XmlDocument();
....
XmlAttribute ^ a = doc->CreateAttribute("unicode");
a1->Value = ??? - what to write here?
...
Stream ^ fs = gcnew FileStream(filename, FileMode::Create);
...
XmlWriter^ writer = gcnew XmlTextWriter(fs, gcnew UTF8Encoding);
How can I force to write the attribute as &#x4c; and not as &amp;x4c;?

Thanks for any help in advance

Tim
Nov 25 '06 #1
4 8369
Tom Fields wrote:
But in some cases, I need the '&' as '&' and not as &amp;.

Example: <glyph unicode="&#x4c;"/>

Some code-snippet:

XmlDocument ^ doc = gcnew XmlDocument();
....
XmlAttribute ^ a = doc->CreateAttribute("unicode");
a1->Value = ??? - what to write here?
...
Stream ^ fs = gcnew FileStream(filename, FileMode::Create);
...
XmlWriter^ writer = gcnew XmlTextWriter(fs, gcnew UTF8Encoding);
How can I force to write the attribute as &#x4c; and not as &amp;x4c;?
What programming language is that? You simply need to set the Value
property to a string with the Unicode characters you need, with C# or J#
you could simply use e.g.
"\u004C"
to have that character in a string literal.

Or you can simply use
"L"
as that is the character with the Unicode code point 76.

There is no need to escape such characters and there is no easy way to
use XmlDocument or XmlTextWriter to enforce escaping of such characters,
you would need your own custom XmlWriter that escapes the characters you
need.
The DOM does not preserve such numeric characters references, it always
gives you the character itself and not the reference.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 25 '06 #2
Thanks for your answer.

Use managed c++.

For ansi-glyphs, I can use <glyph unicode="A"/and so on.
But for unicode glyphs I have to use <glyph unicode="&#x1A12;"/>.

When I use

XmlAttribute ^ a1 = doc->CreateAttribute("unicode");
a1->Value = "\u01A5";

I get the following warning

warning C4566: character represented by universal-character-name
'\u01A5' cannot be
represented in the currencode page (1252)

und the result (in the xml-file is <glyph unicode="?" />.

Tim
Nov 26 '06 #3
Tom Fields wrote:
Use managed c++.

For ansi-glyphs, I can use <glyph unicode="A"/and so on.
But for unicode glyphs I have to use <glyph unicode="&#x1A12;"/>.

When I use

XmlAttribute ^ a1 = doc->CreateAttribute("unicode");
a1->Value = "\u01A5";
Can you try
a1->Value = L"\u01A5";
?
I don't use managed C++ but some examples on managed C++ on MSDN use
that syntax which then converts to a managed .NET System.String literal
I hope. Generally I think the solution is to find a way to write managed
C++ and include/reference Unicode characters in the source code, not to
try to escape Unicode characters the XML way as XML can deal with
Unicode characters without escaping.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 26 '06 #4
On Sun, 26 Nov 2006 15:08:26 +0100, Tom Fields wrote:
Thanks for your answer.

Use managed c++.

For ansi-glyphs, I can use <glyph unicode="A"/and so on.
But for unicode glyphs I have to use <glyph unicode="&#x1A12;"/>.

When I use

XmlAttribute ^ a1 = doc->CreateAttribute("unicode");
a1->Value = "\u01A5";

I get the following warning

warning C4566: character represented by universal-character-name
'\u01A5' cannot be
represented in the currencode page (1252)

und the result (in the xml-file is <glyph unicode="?" />.

Tim
You can use the InnerXml property instead, as this accepts an XML compliant
string such as "&#x01A5;".

Cheers,
Gadget
Nov 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Edward K. Ream | last post: by
27 posts views Thread by EU citizen | last post: by
6 posts views Thread by S. | last post: by
4 posts views Thread by webdev | last post: by
3 posts views Thread by Stilgar[bbs.isca.uiowa.edu] | last post: by
6 posts views Thread by John Sidney-Woollett | last post: by
3 posts views Thread by KvS | last post: by
6 posts views Thread by Raphael.Benedet | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.