|
top
|
Subject: 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
|
|
|