我正在尝试切割一个soap xml响应,以便仅从总体响应中检索真实响应。
纯文本:
------=_Part_406790_188859372.1611576835975
Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <67b0f124-2a07-4c56-a6f2-7db282ad7f65>
<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body>><ns2:Service IdcService="GET_FILE"></env:Body></env:Envelope>
------=_Part_406790_188859372.1611576835975
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <582442cb-3d80-4eaa-b723-0ef901d11c4f>
<?xml version="1.0" encoding="UTF-8" ?> <DATA_DS><G_1><PAYROLL_ACTION_ID>4119</PAYROLL_ACTION_ID><G_2><FILE_FRAGMENT><Feed_V7><REP_CATEGORY_NAME>Blubblub</REP_CATEGORY_NAME><parameters><request_id>234234</request_id><FLOW_NAME>Lalelu 25-01-2021 10:49:33 | Blub</FLOW_NAME><legislative_data_group_id/><effective_date>2021-01-01</effective_date><start_date/><report_category_id>21321</report_category_id><action_parameter_group_id/><changes_only>N</changes_only></parameters></Person></Feed_V7></FILE_FRAGMENT></G_2></G_1></DATA_DS>
------=_Part_406790_188859372.1611576835975--
这就是我想要的:
<?xml version="1.0" encoding="UTF-8" ?><DATA_DS>.....all between.....</DATA_DS>
Groovy试用子字符串:
def bodySize = body.length()
def String subString = body.toString().substring(566)
def otherString = subString.substring(0,76)
println(otherString)
这是一个非常糟糕的做法,但是我已经不知道如何完全动态地检索xml了。
感谢输入(即使只是方法),而不是要求完成的代码,而是使用哪些方法在响应中找到正确的部分) .
off the hip:
String txt = '''
------=_Part_406790_188859372.1611576835975
Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <67b0f124-2a07-4c56-a6f2-7db282ad7f65>
<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body>><ns2:Service IdcService="GET_FILE"></env:Body></env:Envelope>
------=_Part_406790_188859372.1611576835975
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <582442cb-3d80-4eaa-b723-0ef901d11c4f>
<?xml version="1.0" encoding="UTF-8" ?><DATA_DS><G_1>4119</G_1></DATA_DS>
------=_Part_406790_188859372.1611576835975--'''
def matches = ( txt =~ /<?xml.*><DATA_DS>.*</DATA_DS>/ ).findAll()
String match = matches ? matches.first() : null
assert match == '<?xml version="1.0" encoding="UTF-8" ?><DATA_DS><G_1>4119</G_1></DATA_DS>'