How To Execute An XQuery Against Numerous Documents

Issues related to W3C XQuery.
Jamil
Posts: 77

How To Execute An XQuery Against Numerous Documents

Sat Sep 10, 2011 1:06 am

I have created an XQuery to identify erroneous nodes and line numbers they're on for a single document. It looks something like this:

for $name in doc("doc01.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:tokenize(fn:base-uri(), "/")[fn:last()]}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

My issue is that I have hundreds of files, and I do not want to edit this hundreds of times. I cannot simply do something like this: doc("*.xml").

Do I have any other options here?

TIA
Jamil
Posts: 77

Re: How To Execute An XQuery Against Numerous Documents

Sat Sep 10, 2011 3:18 am

I believe I got this partially working now with a minor change as follows:

for $name in collection("file:///c:/Temp?select=*.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:tokenize(fn:base-uri(), "/")[fn:last()]}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

The issue I face now is that the fn:base-uri() function is returning the same document and not the current one from the collection. This makes the results I get useless.
Jamil
Posts: 77

Re: How To Execute An XQuery Against Numerous Documents

Sat Sep 10, 2011 3:35 am

I resolved this on my own.

The solution was the following:

for $name in collection("file:///c:/Temp?select=*.xml")//*[@SomeRandomAttribute="SomeRandomValue"]
where fn:count($name/elementThatMustExist)=0
return <match filename="{fn:document-uri(fn:root($name))}" node="{fn:name($name)}" line="{saxon:line-number($name)}"/>

One last thing that I cannot seem to figure out--

Is there a way that I can expand the line length of the output sequence in oXygen 13? My output from this XQuery is being wrapped at something like 80 characters. There is no need to wrap at all, since I have a wide screen. It makes it difficult to read the results.
Radu
Posts: 5088

Re: How To Execute An XQuery Against Numerous Documents

Tue Sep 13, 2011 2:10 pm

Hi Jamil,

We cannot reproduce the problem with the line width for the result being limited to 80 chars. Probably the XML input files over which you are running the collection query have line widths in their content.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Jamil
Posts: 77

Re: How To Execute An XQuery Against Numerous Documents

Tue Sep 13, 2011 7:42 pm

Here is a screenshot: http://www.file-shop.com/Images/Misc/oXygen_sc.gif

The unneeded attribute wrapping behavior is consistent with both the standalone editor and the Eclipse plug-in. I can find no way to prevent this from happening. I can find no way to specify a line length for documents created via transformation.

There are work-arounds for this, of course (like saving the transformation results as an XML file). Even then I have to manually format the file to remove the wrapped lines. I do not wish to configure oXygen to format every opened XML document (which would take care of the wrapping in this case), because I do not want all XML docs modified upon opening.
Radu
Posts: 5088

Re: How To Execute An XQuery Against Numerous Documents

Wed Sep 14, 2011 12:06 pm

Hi Jamil,

I reproduced the behavior, line breaks are inserted before long attributes.

The only preference we have for formatting is in the Oxygen Preferences->
XML / XSLT-FO-XQuery / XQuery page.
The checkbox is called Format transformer output.
This setting we set to the Saxon 9 XQuery processor and the indentation (and line breaking) is performed exclusively by it.
Unfortunately if you uncheck the checkbox, everything will be outputted on one line.

From what I've checked in the XQuery processor code, the line break for attributes is hard coded to 80 chars so the only option for you is to automatically save the XQuery result to an XML file, open the file and format and indent it in Oxygen.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “XQuery”

Who is online

Users browsing this forum: No registered users and 0 guests