无法加载外部实体错误在Robot Framework中读取SOAP文件时

时间:2018-09-26 12:06:56

标签: robotframework

执行XML解析时出现此错误。 OSError:读取文件'CommandResponseError.xml'时出错:无法加载外部实体“ CommandResponseError.xml”

我的代码::

*** Settings ***
Documentation    Suite description
Library  XML

*** Variables ***
${InputPath}                     ${CURDIR}\\Input
${CommandResponseErrorXML}       CommandResponseError.xml

*** Test Cases ***
Construct Error Code XML To PUSH
    [Documentation]  This KW is used to construct Error XML File
    [Tags]    XML read
     ${XMLNodes}=   Parse XML   ${CommandResponseErrorXML}

我正在使用XML库来解析xml。

这是XML文件。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header/>
    <soap:Body>
        <SendTOPMessages xmlns="http://schemas.turtletech.com/TS2/">
            <messages>
                <RFTOPCommand xmlns="http://schemas.turtletech.com/TS2/">
                    <MessageId>#MessageId</MessageId>
                    <ReceivedTime>1496632500</ReceivedTime>
                    <TOPAddress>#RFCollectorIdentifier</TOPAddress>
                    <LocalWANAddress>0</LocalWANAddress>
                    <LocalLANAddress>4278124157</LocalLANAddress>
                    <RemoteWANAddress>#RemoteWANAddress</RemoteWANAddress>
                    <RemoteLANAddress>#SerialNumber</RemoteLANAddress>
                    <Priority>1</Priority>
                    <TimeToLive>298</TimeToLive>
                    <Mood>0</Mood>
                    <ReturnReceipt>0</ReturnReceipt>
                    <MaxHops>252</MaxHops>
                    <MessageType>4</MessageType>
                    <MessagePayload>#Payload</MessagePayload>
                </RFTOPCommand>
            </messages>
        </SendTOPMessages>
    </soap:Body>
</soap:Envelope>

1 个答案:

答案 0 :(得分:1)

在您的代码示例中:

${XMLNodes}=   Parse XML   ${CommandResponseErrorXML} 

您所指的${CommandResponseErrorXML}依次指代:

${CommandResponseErrorXML}       CommandResponseError.xml. 

如果漫游器文件和CommandResponseError.xml位于同一文件夹中,则此方法将起作用。更改为:

${InputPath}                     ${CURDIR}/Input
${CommandResponseErrorXML}       ${InputPath}/CommandResponseError.xml

,您将添加InputPath来创建Root / Input / file.xml的完整路径。

注意:单个正斜杠在Unix和Windows上均可使用。在我看来,它比反斜杠更受欢迎。即使仅出于可读性原因。