[Engine-devel] Issue with XML namespaces in engine-setup

Ofer Schreiber oschreib at redhat.com
Wed Apr 11 07:51:37 UTC 2012



----- Original Message -----
> Hello,
> 
> The code that we use in engine-setup to modify JBoss AS XML
> configuration files uses the following pattern:
> 
> datasourceStr = '''
>     <datasource ...>
>        ...
>     </datasource>
> '''
> 
> xmlObj.addNodes("//datasource:subsystem/datasource:datasources",
> datasourceStr)
> 
> This looks correct but is in fact generating a incorrect XML
> document,
> as the tags being added are not associated to a namespace. The
> resulting
> XML file will be correct, but the temporary representation in memory
> is
> not. This causes problems if you later, before writing out the
> modified
> file, try to use xpath expressions matching the added nodes: there
> will
> be no match.
> 
> I would suggest that we change the pattern to something like this:
> 
> datasourceStr = '''
>   <any_dummy_tag xmlns="urn:jboss:domain:datasources:1.0">
>     <datasource ...>
>        ...
>     </datasource>
>   </any_dummy_tag>
> '''
> datasourceNodes =
> libxml2.parseDoc(datasourceStr).getRootElement().children
> 
> xmlObje.addNodes("//datasource:subsystem/datasource:datasources",
> datasourceNodes)
> 
> This way both the representation in memory and the resulting file are
> correct.
> 
> Le me know what you think.

As long as it work, I have no problem with that, sounds the right thing to do.
btw- why would you want to use xpath on the "in memory" xml? (In your specific case I mean, not in general)

> 
> Regards,
> Juan Hernandez
> --
> Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
> 3ºD, 28016 Madrid, Spain
> Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat
> S.L.
> _______________________________________________
> Engine-devel mailing list
> Engine-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/engine-devel
> 



More information about the Devel mailing list