|
-
December 4th, 2008, 05:41 AM
#1
C# writing XML through XmlTextWriter
Hi,
I am reading XML from database using
ExecuteXMLReader()
and writing it to a file using
XmlTextWriter(filepath,encoding)
but the problem is that I am getting invalid character error ...
"hexadecimal value 0x03, is an invalid character. Line 3518, position 260."
is there any way to remove invalid characters from XML, I am creating XML in database using "for XML Explicit " and also using <![CDATA[]]> tags from all data.
here is my code
XmlReader XR ;
XmlTextWriter XW ;
XML = ""
cmd = new SqlCommand()
cmd.Connection = sqlConn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp_name"
cmd.Parameters.AddWithValue("@p1", p1)
cmd.Parameters.AddWithValue("@p2", p2)
cmd.CommandTimeout = 0
XR = cmd.ExecuteXmlReader()
XW = New XmlTextWriter(rootPath & fileName, System.Text.Encoding.UTF8)
XW.Formatting = Formatting.Indented
XW.WriteNode(XR, False)
Thanks and please help me out.
Best Regards
Mansoor Aziz
-
December 4th, 2008, 08:14 AM
#2
Re: C# writing XML through XmlTextWriter
What about adding changing it this way:
Code:
XW.WriteString(XR.ReadContentAsString(), False)
At first, I would recommend to inspect return value of XR.ReadContentAsString() to see what exactly have you read.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|