XML Parsing

G

Girish

Hello,

I have a xml file which is as follows:

<pids>
<Parameter_Class>
<Parameter Id="pid_031605_093137_283">
<Identifier>$0000</Identifier>
<Type>PID</Type>
<Signal><![CDATA[Parameter Identifiers Supported - $01
to $20]]></Signal>
<Description><![CDATA[This PID indicates which
legislated PIDs]]></Description>
..............
...............

Can anyone please tell me how to get content of <Signal> tag.. that
is, how to extract the data "![CDATA[Parameter Identifiers Supported -
$01 to $20]]"

Thanks,
Girish...
 
L

Lie Ryan

Hello,

I have a xml file which is as follows:

<pids>
<Parameter_Class>
<Parameter Id="pid_031605_093137_283">
<Identifier>$0000</Identifier>
<Type>PID</Type>
<Signal><![CDATA[Parameter Identifiers Supported - $01
to $20]]></Signal>
<Description><![CDATA[This PID indicates which
legislated PIDs]]></Description>
..............
...............

Can anyone please tell me how to get content of <Signal> tag.. that is,
how to extract the data "![CDATA[Parameter Identifiers Supported - $01
to $20]]"

Thanks,
Girish...

The easy one is to use re module (Regular expression).

# untested
import re
signal_pattern = re.compile('<Signal>(.*)</Signal>')
signals = signal_pattern.findall(xmlstring)

also, you may also use the xml module, which will be more reliable if you
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,297
Messages
2,571,529
Members
48,249
Latest member
reactnativeexpert

Latest Threads

Top