Click here to Skip to main content
15,884,074 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an xml string here from which I need to identify the values and leave out names from it. The logic I thought is to extract all strings which are in between of
> and </.

Then remove any extracted substring which has  >,< or </ in it


XML string is:

<ServiceInstanceUpdateAck xmlns='http://www.loremipsum.com/'>
  <Context>
    <Attribute name='Atri1'>A1</Attribute>
    <Attribute name='Atri2'>A2</Attribute>
  <Attribute name='Atri3'>A3</Attribute>
  </Context>
  <Operation>DEPROVISION</Operation>
  <Status>SUCCESS</Status>
  <Error message='No Error' majorErrorCode='E_NONE' minorErrorCode='E_NONE'/> 
  <Service>
    <Id>11233334</Id>
  </Service> 
</ServiceInstanceUpdateAck>



What will be the python code for that? I am learning python and not that good with strings yet. Any help is appreciated.
Posted
Updated 18-Jan-16 18:18pm
v2
Comments
_Asif_ 19-Jan-16 2:32am    
The correct way of doing this is to use XML parser. I wonder why are you not using it. Did you look at this http://stackoverflow.com/questions/14153988/how-should-i-parse-this-xml-string-in-python?

1 solution

You should not treat XML in this way, use a proper XML parser such as 20.6. xml.dom — The Document Object Model API &mdash; Python 3.3.6 documentation[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900