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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> - Issue with Processing Instruct... (2)
-> ->Issue with Processing Ins...
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Bruce CantorSubject: Issue with Processing Instruction and DTD Reference in XML Document
Author: Bruce Cantor
Date: 11 Mar 2024 12:13 PM
Hello Forum,

I'm encountering a challenge with an XML document that includes both a processing instruction and a reference to a DTD (Document Type Definition). The issue arises when I need to deliver this XML file to a web service that does not accept any processing instructions within the file but requires the presence of the DTD reference.

Here's the problem:

When attempting to remove the processing instruction from the XML file, the DTD reference is also removed, which is essential for the document to be validated correctly.

I've tried using the following code snippet to remove the processing instruction:

declare variable $request := /;

declare variable $filteredRequest :=
if (exists($pi)) then
copy $newDoc := $request modify delete node $newDoc/processing-instruction('Original-FileName') return $newDoc
else
$request;

However, this code not only removes the processing instruction but also eliminates the DTD reference.

I'm seeking guidance on how to resolve this issue. Is there a way to remove the processing instruction without affecting the DTD reference? Any insights or suggestions would be greatly appreciated.

Thank you in advance for your assistance.

Attached is a simplified input document.


DocumentsampleDocForForum.xml
input for transformation

Posttop
Ivan PedruzziSubject: Issue with Processing Instruction and DTD Reference in XML Document
Author: Ivan Pedruzzi
Date: 25 Apr 2024 01:18 AM
This message was sent privately to Bruce on March 13.

Bruce,

stripping the PI is simple the code below shows how to.

The DOCTYPE declaration is completely a different problem. DOCTYPE are not visible to XQuery or XSLT, they are resolved by the XML parser, let me elaborate
XML is a set of bytes --->
[XML Parser] ---> XML Node model (elements, attributes, text nodes, processing instructions)
[XQuery Processor] ---> XQuery Model (items, nodes, …)

After the XML Parser convert the raw text into a node model, the DOCTYPE declaration is resolved.

DOCTYPE is a relic of the past, I am really surprise that cXML still forces use of DTD versus using namespace.

If your source XML document is a file, we could come up with a strategy that reads the document as line of texts, extracts the DOCTYPE and then using serialize-to-url to set DOCTYPE.


Code to strip the PI and generate a specific DOCTYPE. This is like an identity transform in XSLT, instead of matching template it uses recursion.

declare function local:copy($input as item()*) as item()*
{
for $node in $input
return
typeswitch($node)
case document-node() return document { local:copy($node/node()) }
case processing-instruction() return ()
case element() return
element {name($node)}
{
for $att in $node/@* return attribute {name($att)} {$att},
for $child in $node return local:copy($child/node())
}
default return $node
};

declare option ddtek:serialize "indent=yes,doctype-system='h...t...t...p://xml.cXML.org/schemas/cXML/1.2.014/cXML.dtd'";

local:copy(/)



Ivan Pedruzzi
Stylus Studio Team

   
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.