elementtree

appending xml node with subnodes of sam name

appending xml node with subnodes of sam name Question: I have key-value pairs: task_vars = ‘{"BNS_DT": "20220831","DWH_BD": "dwh_bd=2022-08-31","LAYR_CD": "STG"}’ with which I would like to generate subnodes variable: tsk_var = ET.fromstring("""<variable><name></name><value></value></variable>""") and then append variables node in: payload = ET.fromstring("""<task-launch><variables></variables><name>{}</name></task-launch>""".format(task_name)) I loop though the key-values and try to append variables node: tsk_vars = json.loads(task_vars) for …

Total answers: 1

xml parsing with extra 'n' and whitespaces using lxml library

xml parsing with extra 'n' and whitespaces using lxml library Question: I wrote a python program with lxml library to parse a xml file using its xpath. The value and xpath are all correct but it returns many ‘n’ and white spaces just like the xml file’s formatting. here is my code: from lxml import …

Total answers: 1

xpath error, XPath position >= 1 expected

xpath error, XPath position >= 1 expected Question: I am trying to parse a xml from a string. Below is the xml in the string. <xc:Application class="bril::lumistore::Application" id="111" instance="0" logpolicy="inherit" network="local" service="lumistore"> <ns4:properties xsi_type="soapenc:Struct"> <ns4:datasources soapenc_arrayType="xsd:ur-type[1]" xsi_type="soapenc:Array"> <ns4:item soapenc_position="[0]" xsi_type="soapenc:Struct"> <ns4:properties xsi_type="soapenc:Struct"> <ns4:bus xsi_type="xsd:string">brildata</ns4:bus> <ns4:topics xsi_type="xsd:string">tcds,beam,bestlumi,bcm1fagghist,bcm1flumi,bcm1fbkg,pltaggzero,pltlumizero,hfoclumi,hfOcc1Agg,bunchmask,ScopeData,atlasbeam,hfetlumi,hfEtSumAgg,hfafterglowfrac,hfEtPedestal,dtlumi,bunchlength,radmonraw,radmonflux,radmonlumi,pltslinklumi,bcm1futca_bkg12,bcm1futca_background,bcm1futcalumi,remuslumi,remuslumi_5514,remuslumi_5515,remuslumi_5516,remuslumi_5517,bcm1futca_agg_hist</ns4:topics> </ns4:properties> </ns4:item> </ns4:datasources> <ns4:maxstalesec xsi_type="xsd:unsignedInt">30</ns4:maxstalesec> <ns4:checkagesec xsi_type="xsd:unsignedInt">10</ns4:checkagesec> <ns4:maxsizeMB xsi_type="xsd:unsignedInt">120</ns4:maxsizeMB> …

Total answers: 1

Python XML parsing missing element: 'None' vs None

Python XML parsing missing element: 'None' vs None Question: I am parsing an XML file and trying to find some XML tags. I’m looking for the tag personalDataRelated and when running it depending on XML file, I either get one of the two values below : <Element ‘personalDataRelated’ at 0x0000020417C86AC0> None What I do next …

Total answers: 1

python: exception inside try doesn't jump to except

python: exception inside try doesn't jump to except Question: I am trying to search within the EU parliment votes’ description. They are standard xml files. So far I noticed 2 versions of the votes’ result: where the description is text and where it is an url. Fails at this file: https://www.europarl.europa.eu/doceo/document/PV-9-2022-09-12-RCV_FR.xml Works fine on the …

Total answers: 1

Parsing XML with Python Error: argument of type 'NoneType' is not iterable

Parsing XML with Python Error: argument of type 'NoneType' is not iterable Question: The logic here is: If the page-element does not contain "| kasteeltype" then remove page-element, otherwise keep the page-element. #Import ElementTree import defusedxml.ElementTree as ET #Set Tree & Root tree = ET.parse("nlwiki-20221020-pages-meta-current1.xml-p1p134538") root = tree.getroot() #Namespaces NSPage = "{http://www.mediawiki.org/xml/export-0.10/}page" NSRevision = "{http://www.mediawiki.org/xml/export-0.10/}revision" …

Total answers: 1

I want to remove the unwanted sub-level duplicate tags using lxml etree

I want to remove the unwanted sub-level duplicate tags using lxml etree Question: This is the input sample text. I want to do in object based cleanup to avoid hierarchy issues <p><b><b><i><b><i><b> <i>sample text</i> </b></i></b></i></b></b></p> Required Output <p><b><i>sample text</i></b></p> Asked By: Rajeshkanna Purushothaman || Source Answers: Markdown, itself, provides structural to extract elements inside Using …

Total answers: 3

XML file to pandas DataFrame

XML file to pandas DataFrame Question: I have an issue with transforming XML to DataFrame. I have the following sample XML: <Fruits> <Fruit ReferenceDate="2022-09-22" FruitName="Apple"> <Identifier FruitIdentifier="111" FruitBrand="GoldenApple"/> <FruitInformation Country="Turkey" Colour="Green"/> <CompanyInformation CompanyName="GlobalFruits" Location="USA"/> <Languages> <LanguageDependent CountryId="GB" LanguageId="EN"> <FreeText1>Sample sentence 1.</FreeText1> <FreeText2>Sample sentence 2.</FreeText2> </LanguageDependent> </Languages> </Fruit> <Fruit ReferenceDate="2022-09-22" FruitName="Orange"> <Identifier FruitIdentifier="222" FruitBrand="BestOrange"/> <FruitInformation Country="Egypt" …

Total answers: 4

Collect data from an XML file with elementTree

Collect data from an XML file with elementTree Question: I’m developing a script with python that should read some data from an XML file and store it in a list of objects, so they can be treated later. When executing the script, it should collect the data and print the name of the clients and …

Total answers: 2

I can't read an XML file

I can't read an XML file Question: It’s my first time working with XML files, yet I have a problem with a code as simple as: from xml.etree import ElementTree as ET tree = ET.parse(‘some_xml_file.xml’) s = ET.tostring(tree, method = ‘xml’) root = tree.getroot() all I am trying to do here is reading the XML …

Total answers: 1