如何添加XML命名空间到的XmlDocument [英] How to add xmlnamespace to a xmldocument
本文介绍了如何添加XML命名空间到的XmlDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜
我试着去创建一个XML的应该是这样的。
Hi Im trying to create a xml the should look like this
<?xml version="1.0" encoding="iso-8859-1"?>
<MyTestSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Tests>
<Test>
<messaure>1</messaure>
<height>4</height>
</Test>
<Test>
<messaure>4</messaure>
<height>53</height>
</Test>
</Tests>
</MyTestSet>
它不是一个问题,以创建测试或测试的元素,但什么是创造的最好方式MyTestSet,包括命名空间?
使用im C#的XMLDocument
Its not a problem to create the Tests or Test elements, but what is the best way to Create the "MyTestSet" including the namespaces? Im using c# XMLDocument
推荐答案
这对我的作品:
XmlDocument.DocumentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
XmlDocument.DocumentElement.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
如果您要创建您发布整个文档,你可能不想忘记XML声明:
If you want to create the entire document you've posted, you might not want to forget the XML declaration:
XmlDeclaration xml_declaration;
xml_declaration = XmlDocument.CreateXmlDeclaration("1.0", "ISO-8859-1", "yes");
XmlElement document_element = XmlDocument.DocumentElement;
XmlDocument.InsertBefore(xml_declaration, document_element);
在某些情况下,你可能会需要它。
In certain cases you might need it.
这篇关于如何添加XML命名空间到的XmlDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文