I'm using XML EXPLICIT to query some data which may contain some invalid XML
characters. While I'm reading in the data I get an error. Other than
removing the characters before the data is inserted into the database, is
there a way to handle (or omit) reading the invalid characters?
Thanks.
Steve,
Have you thought about escaping the invalid characters? You can escape using
either &<decimal>; or &x<hexadecimal>;
Thanks,
Amol
"SteveISOA" wrote:
> I'm using XML EXPLICIT to query some data which may contain some invalid XML
> characters. While I'm reading in the data I get an error. Other than
> removing the characters before the data is inserted into the database, is
> there a way to handle (or omit) reading the invalid characters?
> Thanks.
|||Amol,
At what point can you escape the invalid characters? I do not want to
modify the existing data in the database, and I'm using a very simple process
of reading and writing the data. It looks something like this:
...
SqlCommand mCommand = new SqlCommand(...); //sp with XML EXPLICIT
...
XmlTextWriter txtWriter = new XmlTextWriter(...);
XmlReader xmlReader = mCommand.ExecuteXmlReader();
while(xmlReader.ReadState != System.Xml.ReadState.EndOfFile)
{
txtWriter.WriteNode(xmlReader,false);
}
...
Thanks again.
Steve
"Amol Kher" wrote:
[vbcol=seagreen]
> Steve,
> Have you thought about escaping the invalid characters? You can escape using
> either &<decimal>; or &x<hexadecimal>;
> Thanks,
> Amol
> "SteveISOA" wrote:
|||Steve,
The escaping should happen before the reader is created. But looks like you
dont have control over the reader creation. Once the reader is created, it
will work off the stream and if you can somehow intercept this stream then
you can replace it there.
Unfortunately invalid characters in XML is not allowed by the XML Spec so
the best solution is if you can fix it when the data gets in and not when you
pull it out. Even if you find a solution to work around this issue,
potentially this is a compatibility issue with other compliant parsers.
Thanks,
Amol
"SteveISOA" wrote:
[vbcol=seagreen]
> Amol,
> At what point can you escape the invalid characters? I do not want to
> modify the existing data in the database, and I'm using a very simple process
> of reading and writing the data. It looks something like this:
> ...
> SqlCommand mCommand = new SqlCommand(...); //sp with XML EXPLICIT
> ...
> XmlTextWriter txtWriter = new XmlTextWriter(...);
> XmlReader xmlReader = mCommand.ExecuteXmlReader();
> while(xmlReader.ReadState != System.Xml.ReadState.EndOfFile)
> {
> txtWriter.WriteNode(xmlReader,false);
> }
> ...
> Thanks again.
> Steve
> "Amol Kher" wrote:
|||You need to ensure that all binary columns or char columns which has invalid
char values like 0xa, 0xb are binary encoded with encodings like binbase64.
Bertan ARI
This posting is provided "AS IS" with no warranties, and confers no rights.
"SteveISOA" <SteveISOA@.discussions.microsoft.com> wrote in message
news:385305A5-2C52-4843-A93B-36D209ED13DD@.microsoft.com...[vbcol=seagreen]
> Amol,
> At what point can you escape the invalid characters? I do not want to
> modify the existing data in the database, and I'm using a very simple
> process
> of reading and writing the data. It looks something like this:
> ...
> SqlCommand mCommand = new SqlCommand(...); //sp with XML EXPLICIT
> ...
> XmlTextWriter txtWriter = new XmlTextWriter(...);
> XmlReader xmlReader = mCommand.ExecuteXmlReader();
> while(xmlReader.ReadState != System.Xml.ReadState.EndOfFile)
> {
> txtWriter.WriteNode(xmlReader,false);
> }
> ...
> Thanks again.
> Steve
> "Amol Kher" wrote:
|||Assuming that the characters are invalid not because of the wrong encoding
(FOR XML results are UTF-16 encoded which means that you need to set it
accordingly on the client side), you have to filter the invalid characters
out in your TSQL code. There may be some non-standard option on the XML
parser that allows you to parse the invalid characters in System.XML, but I
am not sure about that.
Best regards
Michael
"SteveISOA" <SteveISOA@.discussions.microsoft.com> wrote in message
news:385305A5-2C52-4843-A93B-36D209ED13DD@.microsoft.com...[vbcol=seagreen]
> Amol,
> At what point can you escape the invalid characters? I do not want to
> modify the existing data in the database, and I'm using a very simple
> process
> of reading and writing the data. It looks something like this:
> ...
> SqlCommand mCommand = new SqlCommand(...); //sp with XML EXPLICIT
> ...
> XmlTextWriter txtWriter = new XmlTextWriter(...);
> XmlReader xmlReader = mCommand.ExecuteXmlReader();
> while(xmlReader.ReadState != System.Xml.ReadState.EndOfFile)
> {
> txtWriter.WriteNode(xmlReader,false);
> }
> ...
> Thanks again.
> Steve
> "Amol Kher" wrote:
No comments:
Post a Comment