XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Bruce CantorSubject: 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>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE cXML SYSTEM "cXML.dtd"&gt;

&lt;cXML timestamp="2023-02-24T04:44:30-08:00" payloadID="1677242670084-1567548845184757357@10.209.37.72"&gt;

&lt;Response&gt;

&lt;Status code="406" text="Not Acceptable"&gt;The document could not be parsed: Premature end of document while looking for credentials [ANCLS-109544007]&lt;/Status&gt;

&lt;/Response&gt;
&lt;/cXML&gt;



</response-body></response>


UnknownfullResponse.xml
response from API

Unknownerror(2).bmp
Stylus error

Postnext
Ivan PedruzziSubject: problem with Stylus studio trying to evaluate downloaded xml via DTD
Author: Ivan Pedruzzi
Date: 24 Feb 2023 03:21 PM

Download cXML
https://xml.cxml.org/current/cXML_DTDs.zip

Copy cXML.dtd where your XQuery program is

You should be able to parse your document


Ivan Pedruzzi
Stylus Studio Team

Postnext
Bruce CantorSubject: 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?

Postnext
Ivan PedruzziSubject: 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"?>&#10;<!DOCTYPE cXML SYSTEM "cXML.dtd">&#10;&#10;'
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) )

Posttop
Bruce CantorSubject: 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

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.