|
next
|
Subject: problem with Stylus studio trying to evaluate downloaded xml via DTD Author: Bruce Cantor Date: 24 Feb 2023 12:54 PM Originally Posted: 24 Feb 2023 12:47 PM
|
Hi
I am having trouble with an http-response that holds a combination of XML and text.
It looks like that the response itself is an XML doc, but the body is text and I need to read the status from a 'tag' in there.
The script (important part):
declare option ddtek:serialize "method=xml";
let $response := ddtek:http-post($endpoint/@URL,$request, $options)
return $response
will return the full response, but when I change the script to return the body as xml so that I can work with the data, like this:
declare option ddtek:serialize "method=xml";
let $response := ddtek:http-post($endpoint/@URL,$request, $options)
return ddtek:parse($response/*:response/*:response-body/text())
I get an error referring to a missing dtd (the body part refers to a dtd).
How do I make Stylus ignore the dtd reference?
Any help appreciated
/Kind regards Bruce
Attached is the full response and the error I am getting as an image.
Note that opening the response in a browser makes it look as all xml, but it looks like this in Stylus Studio.
<response http-version="HTTP/1.1" status-code="200" reason="Apple"><response-header><header name="content-length" value="401"/><header name="expires" value="Mon, 10 Jan 2000 10:10:10 GMT"/><header name="Strict-Transport-Security" value="max-age=31536000"/><header name="Server" value="Apache"/><header name="Vary" value="Origin,Accept-Encoding,User-Agent"/><header name="Set-Cookie" value="BIGipServerPOOL-SERVICE-2.US.ARIBA.COM=2820722954.64288.0000; path=/; Httponly; Secure"/><header name="cache-control" value="max-age=0"/><header name="Date" value="Fri, 24 Feb 2023 12:44:30 GMT"/><header name="pragma" value="no-cache"/><header name="Content-Type" value="text/html; charset=UTF-8"/></response-header><response-body><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cXML SYSTEM "cXML.dtd">
<cXML timestamp="2023-02-24T04:44:30-08:00" payloadID="1677242670084-1567548845184757357@10.209.37.72">
<Response>
<Status code="406" text="Not Acceptable">The document could not be parsed: Premature end of document while looking for credentials [ANCLS-109544007]</Status>
</Response>
</cXML>
</response-body></response>
fullResponse.xml response from API
error(2).bmp Stylus error
|
next
|
Subject: problem with Stylus studio trying to evaluate downloaded xml via DTD Author: Ivan Pedruzzi Date: 27 Feb 2023 08:51 PM
|
The problem is the base-uri, which is not set when parsing from a string.
The error you see in Stylus Studio is because the current working directory is set to "bin" when Stylus Studio starts,
XML parser ends up trying there.
The test program below shows two possible solutions:
1) store the file on disk where the DTD is located and than parse it using the doc function, where reading a file the the DTD which is reference by a relative path, it is resolved relative to the XML file.
2) Remove the reference to the DTD.
Ivan Pedruzzi
Stylus Studio Team
declare option ddtek:serialize "indent=yes";
declare function local:remove_dtd($xml as xs:string) as xs:string
{
let $dtd:= '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cXML SYSTEM "cXML.dtd"> '
return
if (fn:starts-with($xml, $dtd)) then fn:substring($xml, fn:string-length($dtd)+1)
else $xml
};
declare function local:save_and_parse($xml as xs:string)
{
let $fileName := ddtek:format-dateTime(fn:current-dateTime(), "[Y0001][M01][D01][H01][m01][s01][m03].xml")
let $url:= fn:resolve-uri($fileName, fn:static-base-uri())
return (
ddtek:serialize-to-url($xml, $url, "method=text"),
doc($url)
)
};
let $xml := doc("fullResponse.xml")/response/response-body/string()
return
(: 1) save the the file on disk where the DTD is located :)
(:local:save_and_parse($xml) :)
(: 2) remove the reference to the dtd :)
ddtek:parse( local:remove_dtd($xml) )
|
top
|
Subject: problem with Stylus studio trying to evaluate downloaded xml via DTD Author: Bruce Cantor Date: 28 Feb 2023 01:14 PM
|
Thank you for your support.
I went for the 'save and parse solution', thinking that this would be more a more stabil solution, not dependent on the server formatting exactly the same way for ever.
I added functionality for deleting the temp file after completing the task:
let $response := ddtek:http-post($endpoint/@URL,$request, $options)
let $xmlResponseDoc := local:save_and_parse($response/*:response/*:response-body/text())
let $newResponseDoc := $xmlResponseDoc
return (
(: Write the response to log :)
SAP:WriteResponseToLog($xmlResponseDoc, $LogFileFullPath),
xps_file:delete( base-uri( $newResponseDoc), xs:boolean(1)),
(: Write the outgoing data to Archive :)
ddtek:serialize-to-url(/,
$ArchiveFileFullPath,
"indent=yes, omit-xml-declaration=no,method=xml")
)
kind regards
Bruce
|
|
|
|