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.
<Status code="406" text="Not Acceptable">The document could not be parsed: Premature end of document while looking for credentials [ANCLS-109544007]</Status>
Subject:problem with Stylus studio trying to evaluate downloaded xml via DTD Author:Bruce Cantor Date:27 Feb 2023 07:58 AM
I already tried that.
Problems seems to be that the program wants the dtd to be located here:
C:\Program Files\Stylus Studio X16 XML Enterprise Suite 64-bit\bin\cXML.dtd
So, i tried to copy the dtd to this path and the solves the problem.
However, this leaves the question about where do I copy the file to on the pipeline server? I need this to run on the pipline server.
Is this something that can be solved by using the catalog function, i tried but cannot make it work in Stylus studio, can one use the catalog function with the datadirect xquery prcoessor?
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) )
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),