parsing an string from xml object

Hi

I need to read an XML object wiin an XML file, and then i should take out the specific parts of the XML object for showing to a specific text fields of a panel in my editor window.

the XML object looks like following lines:

<![CDATA[" OpePr1:=..; " " OpePr2:=...;" " OpBh1:=....;"" OpBh2:=..;" " ExCon1:=..;"" ExCon2:=..;" " ExBeh1:=.;"" ExBeh2:=...;" " Invar1:=.;"" Invar2:=.;"]]>

I want to take out those text in between
different tags and shows them in specific text fields on my editor window, for example OpePr1:=… ;OpePr2:=…;
should be shown in the first field and the texts “OpBh1:=…; OpBh2:=…;…” in the second field . ExCon1:=…;
ExCon2:=…; in the next field and so on so forth,

First, going from complete **string **
which has been stored as XML object , to separate lists including OpPre1,OpePre2,…
, and then OpeBeh1,OpeBeh2,… etc,to strings, which each must be viewed
in the specific parts of editor windows is what i intend to do.

second after editing the text in my editor window, i should be able to save to the same place that i have been loaded the text in .xml file!

I would be great if some body have idea on how i can solve this problem.

Thank you in advance!
Massoud.

Hi Massoud,

Massoud Alahdini wrote:

Hi

I need to read an XML object wiin an XML file, and then i should take out the specific parts of the XML object for showing to a specific text fields of a panel in my editor window.

the XML object looks like following lines:

<![CDATA[<OpPr>" OpePr1:=..; "</OpPr> <OpPr>" OpePr2:=...;"</OpPr>

<OpBh>" OpBh1:=....;"</OpBh><OpBh>" OpBh2:=..;"</OpBh2>

<ExCon>" ExCon1:=..;"</ExCon><ExCon>" ExCon2:=..;"</ExCon>

<ExBeh>" ExBeh1:=.;"</ExBeh><ExBeh>" ExBeh2:=...;"</ExBeh>

<Invar>" Invar1:=.;"</Invar><Invar>" Invar2:=.;"</Invar>]]>

I want to take out those text in between different tags and shows them in specific text fields on my editor window, for example OpePr1:=.. ;OpePr2:=....;
should be shown in the first field and the texts "OpBh1:=....; OpBh2:=..;....." in the second field . ExCon1:=..; ExCon2:=..; in the next field and so on so forth,

First, going from complete *string * which has been stored as XML object , to *separate lists *including OpPre1,OpePre2,... , and then OpeBeh1,OpeBeh2,... etc,to* strings*, which each must be viewed in the specific parts of editor windows is what i intend to do.

second after editing the text in my editor window, i should be able to save to the same place that i have been loaded the text in .xml file!

I would be great if some body have idea on how i can solve this problem.

You are probably best of using one of the XML tools to do the parsing for you.

I use amara and I am very happy with it.

There is also elementree I think this is part of Python as of 2.5 or 2.6 and lxml (http://codespeak.net/lxml/)

E.g. with amara after loading the xml file I just do:

    def CreateFromXML(self, xmldoc, logfunction):
        xmlDoc = xmldoc.wine
        if hasattr(xmldoc.wine, 'reseller'):
            self.xmlHasSupplier = True
        else:
            self.xmlHasSupplier = False
        if hasattr(xmldoc.wine, 'producer'):
            self.xmlHasProducer = True
        else:
            self.xmlHasProducer = False

        utilsxml.xmlToTextCtrl((self.wineName, self.stWineName.GetLabel()), xmlDoc,
                        'name', 40, True, log=logfunction)
        utilsxml.xmlToTextCtrl((self.wineName2, self.stWineName2.GetLabel()), xmlDoc,
                        'additionalname', 40, False, log=logfunction)
        utilsxml.xmlToTextCtrl((self.variety, self.stVariety.GetLabel()), xmlDoc,
                        'variety', 40, False, log=logfunction)

"wine" above is an element in the XML file or "name" is an element/attribute of "wine" in that same document etc etc.

the xmlToTextCtrl is just a method which ensures that the length is respected (40 in the above) and put an error into a log if this is not the case or e.g. if "name" is not present in the XML which is a mandatory element ('True' on the 5th parameter).

Hope this helps
Werner