HighTechTalks DotNet Forums  

XmlWriter.WriteString() problem.

Dotnet XML microsoft.public.dotnet.xml


Discuss XmlWriter.WriteString() problem. in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Tom Delany
 
Posts: n/a

Default XmlWriter.WriteString() problem. - 09-04-2007 , 04:08 PM






According to the Microsoft documentation, the .NET class
System.Xml.XmlWriter.WriteString() does the following:

"Character values in the range 0x-0x1F (excluding white space characters
0x9, 0xA, and 0xD) are replaced with numeric character entities (�
through &#0x1F)."

However, when we call WriteString() in an application we have written, we
are seeing the following exception being thrown:

System.ArgumentException: '', hexadecimal value 0x12, is an invalid
character.
at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int 32 ch, Byte*
pDst, Boolean entitize)
at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBl ock(Char* pSrc,
Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlUtf8RawTextWriterIndent.WriteString( String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)

Anyone ever seen anything like this? Any idea what I am doing wrong?

Tom Delany


Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: XmlWriter.WriteString() problem. - 09-05-2007 , 07:38 AM






Tom Delany wrote:
Quote:
According to the Microsoft documentation, the .NET class
System.Xml.XmlWriter.WriteString() does the following:

"Character values in the range 0x-0x1F (excluding white space characters
0x9, 0xA, and 0xD) are replaced with numeric character entities (�
through &#0x1F)."

However, when we call WriteString() in an application we have written, we
are seeing the following exception being thrown:

System.ArgumentException: '', hexadecimal value 0x12, is an invalid
character.
at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int 32 ch, Byte*
pDst, Boolean entitize)
at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBl ock(Char* pSrc,
Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlUtf8RawTextWriterIndent.WriteString( String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)

Anyone ever seen anything like this? Any idea what I am doing wrong?
XmlTextWriter in the .NET framework 1.0/1.1 did that and XmlTextWriter
in the .NET framework 2.0 still does that but the normal XmlWriter you
create with e.g. XmlWriter.Create has been fixed to be compliant with
the XML 1.0 specification and to ensure (by default) that the output is
well-formed and even escaping those characters is not allowed in the XML
1.0 specification.
So use new XmlTextWriter to create an XmlTextWriter or if you want to
use XmlWriter.Create, then use XmlWriterSettings with CheckCharacters
set to false e.g.

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.CheckCharacters = false;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
// ...
}


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
Martin Honnen
 
Posts: n/a

Default Re: XmlWriter.WriteString() problem. - 09-05-2007 , 07:38 AM



Tom Delany wrote:
Quote:
According to the Microsoft documentation, the .NET class
System.Xml.XmlWriter.WriteString() does the following:

"Character values in the range 0x-0x1F (excluding white space characters
0x9, 0xA, and 0xD) are replaced with numeric character entities (�
through &#0x1F)."

However, when we call WriteString() in an application we have written, we
are seeing the following exception being thrown:

System.ArgumentException: '', hexadecimal value 0x12, is an invalid
character.
at System.Xml.XmlUtf8RawTextWriter.InvalidXmlChar(Int 32 ch, Byte*
pDst, Boolean entitize)
at System.Xml.XmlUtf8RawTextWriter.WriteElementTextBl ock(Char* pSrc,
Char* pSrcEnd)
at System.Xml.XmlUtf8RawTextWriter.WriteString(String text)
at System.Xml.XmlUtf8RawTextWriterIndent.WriteString( String text)
at System.Xml.XmlWellFormedWriter.WriteString(String text)

Anyone ever seen anything like this? Any idea what I am doing wrong?
XmlTextWriter in the .NET framework 1.0/1.1 did that and XmlTextWriter
in the .NET framework 2.0 still does that but the normal XmlWriter you
create with e.g. XmlWriter.Create has been fixed to be compliant with
the XML 1.0 specification and to ensure (by default) that the output is
well-formed and even escaping those characters is not allowed in the XML
1.0 specification.
So use new XmlTextWriter to create an XmlTextWriter or if you want to
use XmlWriter.Create, then use XmlWriterSettings with CheckCharacters
set to false e.g.

XmlWriterSettings writerSettings = new XmlWriterSettings();
writerSettings.CheckCharacters = false;
using (XmlWriter xmlWriter = XmlWriter.Create("file.xml",
writerSettings))
{
// ...
}


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.