[Mono-list] Questions about writing an XML document

Loren Bandiera lorenb at mmgsecurity.com
Tue May 9 13:08:02 EDT 2006


Hi Andreas,

>
> Loren Bandiera schrieb:
>>
>> 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

You are correct you can do that with my original example. However the
actual document I'm working with has more than one namespace I need to
specify. For example:

<oval_system_characteristics
  xmlns="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5"
  xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5"
  xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5"
  xmlns:oval-sc="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5"
  xmlns:unix-sc="http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5
oval-definitions-schema.xsd
    http://oval.mitre.org/XMLSchema/oval-system-characteristics-5
oval-system-characteristics-schema.xsd
    http://oval.mitre.org/XMLSchema/oval-system-characteristics-5#unix
unix-system-characteristics-schema.xsd
    http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">

...

</oval_system_characteristics>

XmlDocument.CreateElement() only lets you specify one (at far as I am
aware) so that is why I was using .SetAttribute to do it.

-- 
Loren Bandiera, CISSP <lorenb at mmgsecurity.com>
MMG Security, Inc.




More information about the Mono-list mailing list