[Mono-list] Questions about writing an XML document
atsushi at ximian.com
Tue May 9 07:50:56 EDT 2006
Hmm, it is a bug in XmlAttribute (it appears when xmlDoc.Save(blah) is
added). I made a simple fix which will soon go into svn.
As a workaround, you can use XmlElement.SetAttribute("xsi",
Loren Bandiera wrote:
> I want to write an XML document but there are some parts I'm not sure
> how to go about doing. Specifically namespaces and schemas. Take the
> following example XML:
> <?xml version="1.0" encoding="UTF-8"?>
> <doc xmlns="http://whatever.org/XMLSchema/foo"
> To create it, I've tried doing something like this:
> XmlDocument xmlDoc = new XmlDocument ();
> xmlDoc.AppendChild (xmlDoc.CreateNode
> XmlElement docElement = xmlDoc.CreateElement ("doc");
> docElement.SetAttribute ("xmlns", "http://whatever.org/XMLSchema/foo");
> docElement.SetAttribute ("xmlns:xsi",
> docElement.SetAttribute ("xsi:schemaLocation",
> xmlDoc.AppendChild (docElement);
> XmlElement fooElement = xmlDoc.CreateElement ("foo");
> docElement.AppendChild (fooElement);
> This just fails with an ArguementException saying "Cannot use prefix
> with an empty namespace". That kind of tells me I'm not going in the
> right direction but I haven't had luck finding any proper examples.
> I've seen the XmlNamespaceManager class and tried to use it. I can add
> namespaces but when I write out the document, they are not listed at
> If anyone has any suggestions that would be great.
More information about the Mono-list