如何替换或删除XML中的SPL字符 [英] How to replace or remove the spl character in xml

查看:96
本文介绍了如何替换或删除XML中的SPL字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用xmlwriter创建xml文件的,我认为它可以正常工作,但是当我尝试验证它失败时,bcoz出现如下图所示的spl字符(BOM),就在论坛上消失了,很多人都在劝我使用"SecurityElement .逃脱".不确定如何以及在哪里.有人请引导我从xml文件中删除此spl charecter.

ÿ

如果找到上述符号的代码

看起来像是‘û¿<`

我的代码


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


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();




我可以成功删除版本,但仍然有spl字符.现在卡住了.

有帮助吗?




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

Any help ?

推荐答案

在XmlWriterSettings中,尝试如下所示的ConformanceLevel属性.如果编写者检测到任何违反指定一致性级别的信息项,它将引发异常.在某些情况下,编写器会自动纠正一致性错误.

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.

XmlWriter xmlWrite;
XmlWriterSettings settings = new XmlWriterSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.OmitXmlDeclaration = true;


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.


这篇关于如何替换或删除XML中的SPL字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆