Quote:My html file has a few lines of PHP at the top, but is mainly html.If the .xml it's genrated it will be a string.
The output opens as .xml in my browser, not as a webpage
Then need to pass that string to BS,and not the url.
Again there is nothing i can run ans test with what you post.
from bs4 import BeautifulSoup # Your XML content as a string xml_content = """ <?xml version='1.0' encoding='UTF-8'?><IM415 xmlns="http://www.ros.ie/schemas/customs/IM415"> <Declaration> <MsgType>H1</MsgType> <DeclarationType_1_1>IM</DeclarationType_1_1> <AdditionalDeclarationType_1_2>A</AdditionalDeclarationType_1_2> <LRN_2_5>NIK243104_16nUlp</LRN_2_5> <ValuationInformation> <InvoiceCurrency_4_10>AFA</InvoiceCurrency_4_10> <InvoiceAmount_4_11>5000</InvoiceAmount_4_11> <InternalCurrency_4_12>AFA</InternalCurrency_4_12> </ValuationInformation> <GoodsInformation> <GrossMass_6_5>33300</GrossMass_6_5> <TotalPackageNumber_6_18>1665</TotalPackageNumber_6_18> </GoodsInformation> </Declaration> </IM415> """ # Now use lxml as parser soup = BeautifulSoup(xml_content, 'lxml') print(soup.prettify()) # Save the modified XML to a file with open('test.xml', 'w', encoding='utf-8') as fp: fp.write(soup.prettify())