Re: Parsing XML files as text with collection()
"Imsieke, Gerrit, le-tex" <[email protected]> Fri, 9 Oct 2020 16:24:16 +0200
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Organization | le-tex publishing services GmbH |
| Message-ID | <[email protected]> |
Thanks Martin, I hadn't thought of uri-collection(). I'll use the approach that you suggested. On 09.10.2020 16:17, Martin Honnen wrote: > Am 09.10.2020 um 14:31 schrieb Imsieke, Gerrit, le-tex: > >> I want a recursive directory scan to read in all XML files as unparsed >> text. Then I want to remove the DOCTYPE declaration and named entities >> with replace(). Then I want to parse them with parse-xml(). The reason >> is that all kinds of DTDs at different locations will be referred, but I >> don't have access to these DTDs, and they don't matter for the purpose >> of my analysis. >> >> The documentation says that Saxon will use heuristics to infer the type >> of file. How can I force Saxon to read every *.xml file, although it may >> appear as an XML document, as text? > > With Saxon (tested with HE 10.2 Java) from the command line I have no > problems to use uri-collection and unparsed-text in XQuery or XSLT e.g. > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="#all" version="3.0"> > > <xsl:param name="uri" as="xs:string" > >file:/C:/SomePath/SomeFolder/</xsl:param> > > <xsl:param name="pattern" as="xs:string"><![CDATA[<\?xml > .*?>\s*<!DOCTYPE .*?>]]></xsl:param> > > <xsl:template name="xsl:initial-template"> > <xsl:sequence > select="uri-collection($uri || '?select=*.xml') ! > (unparsed-text(.) => replace($pattern, '') => parse-xml())" > /> > </xsl:template> > > </xsl:stylesheet> > > _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help