[Python] xml.parsers.expat.ExpatError: no element found: line 1, column 0

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to write a script to modify some data in XML files that I need to use for my testing purposes.

    Here is a sample XML that I am picking up to modify.

    <?xml version="1.0" encoding="UTF-8"?>
    <Parent>
    <FlexIDResponseEx xmlns="http://WWW.YYYY.com/SsIkkk">
    <response>
    <Header>
    <Status>0</Status>
    </Header>
    <Result>
    <InputEcho>
    <Name>
    <First>John</First>
    <Last>Doe</Last>
    </Name>
    <Address>
    <StreetAddress1>XX XXX XX XXXXX</StreetAddress1>
    <City>XXXXXX</City>
    <State>XX</State>
    <Zip5>XXXXX</Zip5>
    </Address>
    <Age>0</Age>
    <SSN>XXXXXX</SSN>
    <HomePhone>XXXXXXXXX</HomePhone>
    </InputEcho>
    <UniqueId>XXXXX</UniqueId>
    <NameAddressPhone>
    <Summary>1</Summary>
    <Type>P</Type>
    <Status>C</Status>
    </NameAddressPhone>
    <VerifiedElementSummary>
    <DOB>XXXXXXXX</DOB>
    <DOBMatchLevel>8</DOBMatchLevel>
    </VerifiedElementSummary>
    <ValidElementSummary>
    <SSNValid>0</SSNValid>
    <SSNDeceased>0</SSNDeceased>
    <PassportValid>0</PassportValid>
    <AddressPOBox>0</AddressPOBox>
    <AddressCMRA>1</AddressCMRA>
    <SSNFoundForLexID>0</SSNFoundForLexID>
    </ValidElementSummary>
    <NameAddressSSNSummary>2</NameAddressSSNSummary>
    <ComprehensiveVerification>
    <ComprehensiveVerificationIndex>50</ComprehensiveVerificationIndex>
    <RiskIndicators>
    <RiskIndicator>
    <RiskCode>A</RiskCode>
    <Description>Null</Description>
    <Sequence>1</Sequence>
    </RiskIndicator>
    <RiskIndicator>
    <RiskCode>MS</RiskCode>
    <Description>XXXXXX</Description>
    <Sequence>2</Sequence>
    </RiskIndicator>
    <RiskIndicator>
    <RiskCode>25</RiskCode>
    <Description>XXXXX</Description>
    <Sequence>3</Sequence>
    </RiskIndicator>
    <RiskIndicator>
    <RiskCode>74</RiskCode>
    <Description>The input phone number is associated with a different name and address</Description>
    <Sequence>4</Sequence>
    </RiskIndicator>
    <RiskIndicator>
    <RiskCode>52</RiskCode>
    <Description>The input first name is not associated with input SSN</Description>
    <Sequence>5</Sequence>
    </RiskIndicator>
    </RiskIndicators>
    </ComprehensiveVerification>
    <CustomComprehensiveVerification>
    <ComprehensiveVerificationIndex>0</ComprehensiveVerificationIndex>
    </CustomComprehensiveVerification>
    <InstantIDVersion>1</InstantIDVersion>
    </Result>
    </response>
    </FlexIDResponseEx>
    </Parent>


    Here is my python script I am trying to write

    import os
    from xml.dom.minidom import parse

    fileList = []
    p = os.popen('ls *JJ*',"r")

    while 1:
    line = p.readline()
    if not line: break
    fileList.append(line)

    j = len(fileList)+1


    for i in range(1, j):
    lnFile = open(fileList, "rb")
    tree = parse(lnFile)
    first = tree.find('First')
    first.text = 'YYYY'
    Last = tree.find('Last')
    Last.text = 'ZZZZ'
    tree.write(fileList)
    lnFile.close()


    Here is the stack Trace

    /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 /Users/parser/parse.py
    Traceback (most recent call last):
    File "/Users/parser/pare.py", line 17, in <module>
    tree = parse(lnFile)
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/dom/minidom.py", line 1958, in parse
    return expatbuilder.parse(file)
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/dom/expatbuilder.py", line 913, in parse
    result = builder.parseFile(file)
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/dom/expatbuilder.py", line 211, in parseFile
    parser.Parse("", True)
    xml.parsers.expat.ExpatError: no element found: line 1, column 0

    Process finished with exit code 1

    Continue reading...

Compartilhe esta Página