In one of my xquery, I use doc() function to load a plain xml document and reference it later on. The xquery is called using s9api.
However, due to external requirements, I need to encrypt the XML so the content of it will not be exposed to the user directly. I did this with a very simple encryption schema that is handled by calling a Java method of mine in run-time. The decryption is done in memory (i.e. loading the file from disk, decrypt it as a Java String.)
Now I have a XML file stored in a Java String; what is the best way to pass that xml content into my xquery file so it can reference it?
Thanks a lot.
sry I think I put this in a wrong section of the forum.
Simpliest is probably using XQueryEvaluator.setSource( Source )
You will need a "Source" object built from the string.
One way is using "StreamSource" which can be constructed from an InputStream
The InputStream can be created from a string indirectly using ByteArrayInputStream
Make sure you dont get transcoding errors by converting from your decoded "String" to a byte array. If possible avoid using String if you can get your decryptor to output to a byte instead. Then construct the ByteArrayInputStream, the StreamSource and call setSource().
Thanks a lot, David. I will give it a shot.
Another question: if I reference multiple XMLs, I can only specify one as source.
What's the best alternative for that case?
I am thinking about passing the decrypted content in as an external variable. However, I am not sure what's the best way to convert a string of XML into a xdmitem or xdmvalue.
To get a String as a XdmNode for a variable, follow the same path to get a Source object then use DocumentBuilder.build( Source )
Log in to post a comment.