【发布时间】:2011-03-24 15:46:05
【问题描述】:
我之前曾使用XmlDocument 生成基本的 Xml,但是我正在努力通过代码重新创建以下 XML。主要问题似乎在于将命名空间添加到描述部分。
如何创建以下示例 XML 文件?
<?xml version="1.0"?>
<pndsdc:description
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:pndsterms="http://purl.org/mla/pnds/terms/"
xmlns:pndsdc="http://purl.org/mla/pnds/pndsdc/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://purl.org/mla/pnds/pndsdc/
http://www.ukoln.ac.uk/metadata/pns/pndsdcxml/2005-06-13/xmls/pndsdc.xsd"
>
<dc:identifier encSchemeURI="http://purl.org/dc/terms/URI">http://example.org/my/docs/12345/</dc:identifier>
<dc:title xml:lang="en">Everything you wanted to know about identity, but were afraid to ask</dc:title>
<dc:description xml:lang="en">The article provides a summary of the 2003 White Paper on identity cards for the UK
with a critique from the perspective of several national and international civil liberties organisations.</dc:description>
<dc:subject>Identity cards</dc:subject>
<dc:subject>Civil liberties</dc:subject>
<dc:subject>Human rights</dc:subject>
<dc:type encSchemeURI="http://purl.org/dc/terms/DCMIType" valueURI="http://purl.org/dc/dcmitype/Text">Text</dc:type>
<dcterms:license valueURI="http://creativecommons.org/licenses/by-nc-nd/2.0/uk/" />
<dcterms:rightsHolder>The National Campaign Against Identity Cards</dcterms:rightsHolder>
<dcterms:spatial encSchemeURI="http://purl.org/dc/terms/TGN">World, Europe, United Kingdom</dcterms:spatial>
</pndsdc:description>
代码也可以是found here online。
【问题讨论】:
-
如果可以的话,我推荐使用 Linq to XML 及其 XDocument 类。使用命名空间创建 XML 要容易得多。
-
你应该问一个更直接的问题。你已经得到了什么?你具体有什么困难?
-
我和彼得在一起,我看不出这里有什么困难,所以除了写完整的代码来写上面的文档,有人能回答你的问题吗?
标签: c# .net xml xmldocument