[Mono-list] Questions about writing an XML document

Andreas Färber andreas.faerber at web.de
Tue May 9 12:50:20 EDT 2006


Hi Loren,

Loren Bandiera schrieb:
> 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"
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xsi:schemaLocation="http://whatever.org/XMLSchema/foo.xsd">
>      <foo>bar</foo>
> </doc>
>
> To create it, I've tried doing something like this:
>
> XmlDocument xmlDoc = new XmlDocument ();
> xmlDoc.AppendChild (xmlDoc.CreateNode
> (XmlNodeType.XmlDeclaration,"",""));
>
> XmlElement docElement = xmlDoc.CreateElement ("doc");
> docElement.SetAttribute ("xmlns", "http://whatever.org/XMLSchema/foo");
>   
I believe CreateElement is actually overloaded so that you can give the
namespace directly as an argument without setting it manually
afterwards. :-)

HTH,

Andreas


More information about the Mono-list mailing list