Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

xml tags search and split?

If you have a question or need help, this is the place to be.
Post Reply
eddiex666
Posts: 41
Joined: Fri Sep 12, 2014 10:34 pm

xml tags search and split?

Post by eddiex666 »

Hi Is there any good ways to split a "eg.event.string" with many xml tags?

I have a http request into EG with
<adress>gofy1</adress><number>1234</number>
so I would like to split the tags into vars...

Any easy ways?

Tnx, Eddie
Javier
Experienced User
Posts: 73
Joined: Sun Dec 01, 2013 3:45 pm

Re: xml tags search and split?

Post by Javier »

You can do this with a python script with Element Tree

Code: Select all

import xml.etree.ElementTree as ET

#EXAMPLE STRING
#string = "<adress>gofy1</adress><number>1234</number>"

#EG.EVENT.STRING
string = eg.event.string

#The next line may need to be removed if XML is in the correct format / Already Has a begining and ending tag
string = "<egdata>" + string + "</egdata>"

string = ET.fromstring(string)

for child in string:
    tag = child.tag
    data = child.text
    print "Tag is:",tag
    print "Data is:",data
Post Reply