[Python] XML (RDL) code broken after editing with Python (BS4), how to find error?

Discussão em 'Python' iniciado por Stack, Abril 20, 2025.

  1. Stack

    Stack Membro Participativo

    I did editing RDL (same like XML?) files cleaning them not used Embedded elements. Didn't touch left images. Doing it in Python, sample code looks like below in pseudo view: Input has this header :

    <?xml version="1.0" encoding="utf-8"?>
    <Report xmlns="http://schemas.microsoft.com/sqlserver/report.....
    ....
    ....<!-- RDL definition -->
    <rd:ReportID>b3c5ab10-9fe4-4d15-ae08-da203d00bc77</rd:ReportID>
    </Report>


    Then I do:

    with open(filepath, 'r') as f: #local drive
    data = f.read()
    Bs_data = BeautifulSoup(data, "xml")
    ....
    for item in Bs_data.find_all('EmbeddedImage'):
    if item.get('Name') not in list_keep:
    item.decompose()
    .....
    fileN = open(filepath + '__.xml', 'w')
    fileN.write(str(Bs_data))


    And then after replacing RDL file something wrong happening in VS, like on this picture before and after. ImageData after edit displayed differently in single line and closing tag doesn't work (can see no red color on it). So whole xml got broken. I can't run this report. ImageData in A and B is the same in term of comparison in Notepad++, is it about encoding?? What is the trick I can use, thanks all for hints. Result RDL/XML passed xml validation in any tool/browser, only fails in VS/SSRS project. This is handy picture to compare. ImageData string is 100,000 char long, maybe there is some limitation for VS ??

    Happy Easter. [​IMG]

    In VS you can see that max lenght = 1000b [​IMG]

    Continue reading...

Compartilhe esta Página