I'm trying to write a XML-document programatically.
I need to add <xsd:schema> tag to my document.
Currently I have:
var xmlDoc = new XmlDocument(); var root = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(root); var xsdSchemaElement = xmlDoc.CreateElement("schema"); xsdSchemaElement.Prefix = "xsd"; xsdSchemaElement.SetAttribute("id", "root"); root.AppendChild(xsdSchemaElement); However, this renders to:
<root> <schema id="root" /> </root> How do I get the tag to be <xsd:schema>?
Already tried var xsdSchemaElement = xmlDoc.CreateElement("xsd:schema"); which simply ignores the xsd:.
Edit #1
Added method
private static XmlSchema GetTheSchema(XmlDocument xmlDoc) { var schema = new XmlSchema(); schema.TargetNamespace = "xsd"; return schema; } which is called like xmlDoc.Schemas.Add(GetTheSchema(xmlDoc)); but does not generate anything in my target XML.
No comments:
Post a Comment