Редактирование существующего XML-файла и отправка сообщения через Jboss - PullRequest
0 голосов
/ 21 сентября 2019

У меня есть следующий метод python, который запускается через файл xml и анализирует его, и 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: ParseError at[row, col]: [1,1] Сообщение: содержимое не разрешено в прологе.

Примечание. Я убедился, что до первого тега xml нет символов.

...