We were given a sample document, and need to be able to reproduce the structure of the document exactly for a vendor. However, I\'m a little lost with how C# handles namesp
If you are using Visual Studio 2008 in the Samples folder you'll find a sample addin that let's you paste a XML fragment as Linq2XML code.
Scott Hanselman has a blog post with the details.
I think this is the quickest way to go from a sample XML doc to C# code that creates it.
I personally prefer to use the common XmlElement and its attributes for declaring namespaces. I know there are better ways, but this one never fails.
Try something like this:
xRootElement.SetAttribute("xmlns:xsi", "http://example.com/xmlns1");
You should try it that way
XmlDocument doc = new XmlDocument();
XmlSchema schema = new XmlSchema();
schema.Namespaces.Add("xmlns", "http://www.sample.com/file");
doc.Schemas.Add(schema);
Do not forget to include the following namespaces:
using System.Xml.Schema;
using System.Xml;