Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing BeautifulSoup from converting my XML tags to lowercase

I am using BeautifulStoneSoup to parse an XML document and change some attributes. I noticed that it automatically converts all XML tags to lowercase. For example, my source file has <DocData> elements, which BeautifulSoup converts to <docdata>.

This appears to be causing problems since the program I am feeding my modified XML document to does not seem to accept the lowercase versions. Is there a way to prevent this behavior in BeautifulSoup?

like image 757
RexE Avatar asked Feb 20 '09 01:02

RexE


2 Answers

No, that's not a built-in option. The source is pretty straightforward, though. It looks like you want to change the value of encodedName in Tag.__str__.

like image 180
Andrew B. Avatar answered Oct 20 '22 00:10

Andrew B.


  • Simple Answer
    • change (default html.parser) to xml parser
      • code: soup = BeautifulSoup(yourXmlStr, 'xml')
  • Detailed Explanation
    • refer my answer in another post
like image 4
crifan Avatar answered Oct 20 '22 01:10

crifan