如何用C#從XML中刪除所有名稱空間?我正在尋找干凈、優雅和智能的解決方案來從所有XML元素中刪除名稱空間?這樣做會有什么作用呢?定義的接口:public interface IXMLUtils{
string RemoveAllNamespaces(string xmlDocument);}從以下位置刪除NS的示例XML:<?xml version="1.0" encoding="utf-16"?><ArrayOfInserts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:
xsd="http://www.w3.org/2001/XMLSchema">
<insert>
<offer xmlns="http://schema.peters.com/doc_353/1/Types">0174587</offer>
<type2 xmlns="http://schema.peters.com/doc_353/1/Types">014717</type2>
<supplier xmlns="http://schema.peters.com/doc_353/1/Types">019172</supplier>
<id_frame xmlns="http://schema.peters.com/doc_353/1/Types" />
<type3 xmlns="http://schema.peters.com/doc_353/1/Types">
<type2 />
<main>false</main>
</type3>
<status xmlns="http://schema.peters.com/doc_353/1/Types">Some state</status>
</insert></ArrayOfInserts>在調用RemoveAllNamesspace(XmlWithLotOfns)之后,我們應該得到: <?xml version="1.0" encoding="utf-16"?>
<ArrayOfInserts>
<insert>
<offer >0174587</offer>
<type2 >014717</type2>
<supplier >019172</supplier>
<id_frame />
<type3 >
<type2 />
<main>false</main>
</type3>
<status >Some state</status>
</insert>
</ArrayOfInserts>預編寫的解決方案語言是.NET 3.5SP1上的C#。
- 3 回答
- 0 關注
- 589 瀏覽
添加回答
舉報
0/150
提交
取消