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 next topicNext 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

 
Go 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.