Namespace attribute placement by Genshi

28 views
Skip to first unread message

glo...@gmail.com

unread,
Nov 6, 2013, 8:28:42 AM11/6/13
to gen...@googlegroups.com
Hi,

I'm trying to do generate a template from a string, containing legacy (i.e. I am not to change it) xml with namespace declarations, like this:

templatestr = """
<my_output xmlns="http://some-address.com/sub/nr" xmlns:p="http://some-address.com/sub/nr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=http://some-address.com/sub/nr http://some-address.com/sub/nr/src/xml/file.xsd" p:majorVersion="0" p:minorVersion="00" p:version="version 0.00">
  <elements xmlns:py="http://genshi.edgewall.org/">
<py:for each="el in elements">
${el}
</py:for>
</elements>
</my_output>
"""

tpl = MarkupTemplate(templatestr)
str = tpl.generate(elements=list_with_xml_markup_strings)
for x in str.serialize():
print x

The elements passed to the template are of the form:
el = '<element p:attribute="something"><child/>...</element>
'
However, in the output, even if the list from which to generate elements is empty, genshi seems to remove the xmlns:p declaration from my root element, and add p: attributes to all the elements in the template (but not the ones passed by generate() ).
Basically, it looks like this:

<p:my_output xmlns="http://some-address.com/sub/nr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=http://some-address.com/sub/nr http://some-address.com/sub/nr/src/xml/file.xsd" p:majorVersion="0" p:minorVersion="00" p:version="version 0.00">
<p:elements xmlns:py="http://genshi.edgewall.org/">

etcetera.

Is this expected behaviour? And if yes, what should I do to have the attributes remain in place?


cheers,
jorrit

Simon Cross

unread,
Nov 19, 2013, 3:00:52 PM11/19/13
to gen...@googlegroups.com
Hi

On Wed, Nov 6, 2013 at 3:28 PM, <glo...@gmail.com> wrote:
> templatestr = """
> <my_output xmlns="http://some-address.com/sub/nr" xmlns:p="http://some-
> address.com/sub/nr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation=http://some-address.com/sub/nr http://some-
> address.com/sub/nr/src/xml/file.xsd" p:majorVersion="0" p:minorVersion="00"
> p:version="version 0.00">

It's a bit hard to tell what it is going on in the example above -- it
seems to have been hand edit to remove some presumably-secret domain
names but there are now copy and paste errors.

Could you perhaps put up a working code snippet and examples of the
desired and received output and I can maybe comment more?

Schiavo
Simon
Reply all
Reply to author
Forward
0 new messages