Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Am creating an xml file using xmlwriter,i thought it works fine but when i try to validate it fails bcoz there is spl character (BOM) appears like below,just gone thru forum seen lot of people adive me to use "SecurityElement.Escape". Am not sure how and where.Some one please guide me to remove this spl charecter from the xml file.



if found the code for the above symbol

It look like `<`

My Code


C#
XmlWriter xmlWrite;
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
xmlWrite = XmlWriter.Create(@"c:\test.xml",settings);
xmlWrite.WriteStartElement("metadata");
xmlWrite.WriteElementString("story", story);
xmlWrite.Close();



i can succesfully remove the version but still the spl characters are there . Am stuck now.

Any help ?
Posted
Updated 8-Mar-12 14:41pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Mar-12 21:26pm    
What is the exact BOM value (what UTF is indicated by it and does it match the encoding specified in XML prolog? If this is UTF-8, you can work without BOM as all characters in the prolog are ASCII and the ASCII code and UTF-8 code are identical in the ASCII subset of the characters.
--SA
shan1395 8-Mar-12 22:00pm    
hi SA,

this is the value i mean code for the char <
Sergey Alexandrovich Kryukov 8-Mar-12 22:43pm    
Not clear. There are several characters here. What do you mean code? Each character has its Unicode code point, but the code point are represented on the computer using different UTFs. As simple as that. For example, when you type them in this page, they are represented as UTF-8, where each character takes different number of bytes. I think you problem is to understand your problem.
--SA
shan1395 8-Mar-12 22:01pm    
I couldn't able to post the code here,it automatically change in to char
Sergey Alexandrovich Kryukov 8-Mar-12 22:44pm    
Learn some HTML. You need to use character entities. Besides, you code should not contain data.
--SA

In XmlWriterSettings, try ConformanceLevel property as below. If the writer detects any information items that would violate the specified level of conformance, it throws an exception. In some cases, the writer automatically corrects the conformance error.

C#
XmlWriter xmlWrite;
XmlWriterSettings settings = new XmlWriterSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.OmitXmlDeclaration = true;
 
Share this answer
 
Comments
shan1395 8-Mar-12 21:31pm    
Thanks GanesanSenthilvel, i tried what you suggested but still am getting the spl char in the xml file.its freak me out now.
Here[^] is a method that you can use to validate special characters on your XML. The only drawback of this is that if you have plenty of nodes on your XML, it might take time to validate all of them, since what happens here is that, you are checking every character of the value of each of the node.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900