Re: Construct an XdmMap from JSON file (for use as XQuery context item)
Andreas Sewe <andreas_sewe-+IBl0H0C+Lsf95zv9F5CbQC/[email protected]>
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <[email protected]> |
Michael Kay wrote:
> No, there's no equivalent to the DocumentBuilder at the s9api level. One
> approach is simply to issue a query that invokes fn:json-doc() on a URI
> supplied as a parameter.
Yes, in most cases that would work, but in my case I need to bind the
JSON content to the query's context item.
Essentially, I am implementing a Maven plug-in modeled on the
xml-maven-plugin's transform goal [1], only for XQuery. Something like
the following:
<plugin>
<artifactId>xquery-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>query</goal>
</goals>
</execution>
</executions>
<configuration>
<querySets>
<querySet>
<mainModule>src/main/xquery/query-xml.xq</mainModule>
<includes>
<include>**/*.xml</include>
</includes>
</querySet>
<querySet>
<mainModule>src/main/xquery/query-json.xq</mainModule>
<includes>
<include>**/*.json</include>
</includes>
</querySet>
</querySet>
</configuration>
</plugin>
> You can also do something like:
>
> XdmFunctionItem parseJson = XdmFunctionItem.getSystemFunction(proc, new QName(NamespaceConstant.FN, "parse-json"), 1);
> XdmMap result = (XdmMap) fi.call(proc, new XdmAtomicValue("{\"colour\":\"green\"}"));
Thanks, that looks exactly like what I am after and is not too
low-level. :-)
Also, good to know that the Xdm* constructors are meant to be called by
client code without any factories in the mix (as is often the case when
dealing with XML-APIs).
Best wishes,
Andreas
[1]
<https://www.mojohaus.org/xml-maven-plugin/examples/transform-basic.html>
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEENQNppz9Dfe6AGYg4LHyYYW0ubKsFAl8peC8ACgkQLHyYYW0u bKthcw/8CpcJuVZruOqCd+wYRrsmP2sT/LW89BrFNglhpdaIngQzVJ8KYYl1SeZq RyqfvQl0o+PqavSQUcYX40fnl5/aGumK7qNTSHB1tWcarchS7RZ9zV8jyjEkNfVU MKBZaltQeYcyVE9uXQh/SGyB4pqbtB4IxEi3FytZRS5Jc1vWI/z8ppZPfH9GTV2M N+9WyJYsX7Be66QScb2nx2dbvaHJD2/kvxJfML0FogasSvxMsGnsnL1r+CVt324r xhvODd3GX3MAdoBWE9G8sDpVaI07rWSTDFTICfYl616oqozrxqKQ90paVxzmPQT5 CemedeTmPejJJS3qytNMfFkJxVP2EvUidBSvp20CSXihBXBJe+7a9DWDuSC9QkG0 oXCUSHPFEio1XrJ7kgL/1gB+mtrc2qUgl3rfJj6zo2x8SQiljJZZhRr8zgYBmd2h 6RmrGcVHy3k2tYiJRaXI/pxh7GDIVmHUVOIOlxGjaOdzAmySsZ4BHk0OcCQnDcOs M0sqypauRrzADqJkWyQOLQ23NSWb/6RArdXeRu4ji+qYDUAry2Ny2HMyvsXvcxgt O4IijeI9jMN+zN1AJuXqKnevDLELD0H3AIxfJI8443Uan+LxH/McAM/Q8ZhilWoL SpiXpbwJ1qzHzjUKjSchl3t3X3Ep3OVhXRKeNCTvOT+5vArUhsk= =2uxQ -----END PGP SIGNATURE-----