编辑现有的XML文件并通过Jboss发送帖子

问题描述 投票:0回答:1

我有以下通过xml文件运行并解析的python方法,以及TRIES来编辑字段:

    import requests
import xml.etree.ElementTree as ET
import random

def runThrougheTree():
    #open xml file
    with open("testxml.xml") as xml:
        from lxml import etree
        #parse
        parser = etree.XMLParser(strip_cdata=True, recover=True)
        tree = etree.parse("testxml.xml", parser)
        root= tree.getroot()
        #ATTEMPT to edit field - will not work as of now
        for ci in root.iter("CurrentlyInjured"):
            ci.text = randomCurrentlyInjured(['sffdgdg', 'sdfsdfdsfsfsfsd','sfdsdfsdfds'])
        #Overwrite initial xml file with new fields  - will not work as of now
        etree.ElementTree(root).write("testxml.xml",pretty_print=True, encoding='utf-8', xml_declaration=True)

        #send post (Jboss)
        requests.post('http://localhost:9000/something/RuleServiceImpl', data="testxml.xml)



def randomCurrentlyInjured(ran):
    random.shuffle(ran)
    return ran[0]







#-----------------------------------------------
if __name__ == "__main__":
    runThrougheTree()

编辑的XML文件:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rule="http://somewebsite.com/" xmlns:ws="http://somewebsite.com/" xmlns:bus="http://somewebsite.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:Respond>
         <ws:busMessage>
            <bus:SomeRef>insertnumericvaluehere</bus:SomeRef>
            <bus:Content><![CDATA[<SomeDef>
  <SomeType>ABCD</Sometype>
  <A_Message>
      <body>
        <AnonymousField>
          <RefIndicator>1111111111111</RefIndicator>
          <OneMoreType>HIJK</OneMoreType>
          <CurrentlyInjured>ABCDE</CurentlyInjured>
        </AnonymousField>
      </body>
  </A_Message>
</SomeDef>]]></bus:Content>
            <bus:MessageTypeId>somenumericvalue</bus:MessageTypeId>
         </ws:busMessage>
      </ws:Respond>
   </soapenv:Body>
</soapenv:Envelope>

问题:

  1. 该字段未被编辑。
  2. Jboss错误:由以下原因引起:javax.xml.stream.XMLStreamException:[row,col]处的ParseError:[1,1]消息:序言中不允许包含内容。

注意:我确保第一个xml标记之前没有字符。

python jboss lxml soapui
1个回答
0
投票
最后,我无法使用lxml,elementtree来编辑字段/以如下方式发布到Jboss:
© www.soinside.com 2019 - 2024. All rights reserved.