We're documenting Amara/Akara projects at http://wiki.xml3k.org. You
can visit Amara's tutorial: http://wiki.xml3k.org/Amara/Tutorial There
you have go xml_append examples (if you're using amara.parse function)
You can use too bindery methods that are much more pythonic because
you can use xml elements as python objects.
-- lm
> Could anyone provide some suggestions as to where I can find the info
> I need?
>
> --
> You received this message because you are subscribed to the Google Groups "akara" group.
> To post to this group, send email to ak...@googlegroups.com.
> To unsubscribe from this group, send email to akara+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/akara?hl=en.
>
>
For example, I'm doing this:
from amara import bindery
doc = bindery.parse(''.join(open('./StartupStreams.xml').readlines()))
top = doc.Root
streamContainer = doc.Root.StartupStreams
I've now got my XML file in a nice, easy to navigate form. I can list
the current contents of the tree with:
stream = streamContainer.StartupStream
for strm in stream:
print strm.Application, strm.StreamName
and this shows me that everything looks good.
Now, I can define the XML I want to insert easily enough:
XML = """<StartupStream>
<Application>myAppName</Application>
<MediaStreamType>liverepeater</MediaStreamerType>
<StreamName>MyLiveStream</StreamName>
</StartupStream>"""
and I can convert into a node that Amara understands:
node = bindery.parse(XML)
Now is where I'm lost. I've tried:
streamContainer.xml_append(streamContainer.xml_element_factory(None, node))
and I've tried:
streamContainer.xml_append(streamContainer.xml_element_factory(None, XML)
but no matter what I try when I iterate through the tree again I never
see the element I've tried to insert. I must be missing something very
simple, which I'm hoping someone can point out to me.
On 09/23/2011 11:53 AM, Uche Ogbuji wrote:
> Hello.
Or if the fragment was a parsed node:
MORE_XML = """<StartupStreams>
<StartupStream>
<Application>myAppName2</Application>
<MediaStreamType>liverepeater2</MediaStreamType>
<StreamName>MyLiveStream2</StreamName>
</StartupStream>
<StartupStream>
<Application>myAppName3</Application>
<MediaStreamType>liverepeater3</MediaStreamType>
<StreamName>MyLiveStream3</StreamName>
</StartupStream>
</StartupStreams>"""
fragment_node = bindery.parse(MORE_XML)
# I'm going to add only the second StartupStream
streamContainer.xml_append(fragment_node.StartupStreams.StartupStream[1])
doc.xml_write()
>>>
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<StartupStreams>
<StartupStream>
<Application>App name 1</Application>
<MediaCasterType>liverepeater</MediaCasterType>
<StreamName>MyLiveStream</StreamName>
</StartupStream>
...
... more StartupStream entries
...
<StartupStream>
<Application>myAppName3</Application>
<MediaStreamType>liverepeater3</MediaStreamType>
<StreamName>MyLiveStream3</StreamName>
</StartupStream></StartupStreams>
</Root>
-- lm
>> HTH
>>
>> --
>> Uche Ogbuji http://uche.ogbuji.net
>> Weblog: http://copia.ogbuji.net
>> Poetry ed @TNB: http://www.thenervousbreakdown.com/author/uogbuji/
>> Founding Partner, Zepheira http://zepheira.com
>> Linked-in: http://www.linkedin.com/in/ucheogbuji
>> Articles: http://uche.ogbuji.net/tech/publications/
>> Friendfeed: http://friendfeed.com/uche
>> Twitter: http://twitter.com/uogbuji
>> http://www.google.com/profiles/uche.ogbuji
>>
>