I have used XmlDocument before to generate basic Xml before, however I am struggling to recreate the following XML via code. The main problem seems to be around adding the namespaces to the description section.
How do I create the following example XML file?
<?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>
Code can also be found here online.
Don’t worry about creating namespace declarations. Just make sure that every element that you create is in the right namespace. The
XmlDocumentwill create the namespace declarations for you. So:and so on. It’s usually easier to create a
Dictionary<string, string>containing the namespaces keyed by prefix, and then do something like: