I have to interact with a repository of documents, where each document is inserted with metadata contained in an XML document.
Now, at some point, this metadata must be generated from scratch. I thought that using a class to create this XML will be the best solution.
I generate the class using the Developer Command Prompt, this is the result:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://example.com/metadata")]
[System.Xml.Serialization.XmlRootAttribute(ElementName = "Metadata", Namespace="http://example.com/metadata", IsNullable=false)]
public partial class XmlMetadata {
private System.Xml.XmlElement[] anyField;
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlElement[] Any {
get {
return this.anyField;
}
set {
this.anyField = value;
}
}
}
This class shoud be able to generate XML documents like this:
<?xml version="1.0" encoding="utf-8"?>
<md:Metadata xmlns:md="http://example.com/metadata">
<md:Cert>0001</md:Cert>
<md:Model>Test</md:Model>
<md:Created>2015-05-21</md:Created>
</md:Metadata>
QUESTION 1: Is this class enough descriptive to generate this kind of XML documents? (Note the prefix on every tag and how every tag have a different name, also I must be able to insert any number of elements)
QUESTION 2: How I insert elements in an instance of this class? This elements have the form of a KeyValuePair, where the key represent the tag name.
QUESTION 3: How do I serialize this class into a stream and into a Base64 string from there?
Thanks in advance