简体   繁体   中英

Parsing XMLString with libxml2 in Python

I have an XML which is in the form of a string which my parser can't work with. Concretely it has all the XML tags but it is a string instead of an XML file. It should be first converted to an XML file. I have already googled and came across a similar question on SO but that deals with libxml2's C++ api. I am working in python.

libxml2 can parse strings that contain xml .

import libxml2
libxml2.parseDoc('<?xml version="1.0"?> <data> <something>Baaahh!</something> </data>')

this returns a valid xml object.

If you want to read a whole file you can use libxml2.parseFile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM