|
-
Jun 12th, 2008, 04:27 PM
#1
Thread Starter
Hyperactive Member
XQuery with Nested Return
Hello I was wondering if someone could help me with this awfully frustrating conundrum. What I am trying to do is have the return return both a single value and the results of another xquery. The tricky part is that I do not want to return the content as XML but rather in plain text.*
My specific case is that I want to find every enumeration in an XSD, print out the name of the datatype, and underneath it the list of all its possible values.
Now this works:
Code:
declare namespace xsd = "http://www.w3.org/2001/XMLSchema";
declare variable $url := ".....";
declare variable $src := doc($url);
declare variable $nl := codepoints-to-string(10);
for $type in $src//xsd:simpleType[.//xsd:enumeration]
let $typeName := string($type/@name)
return <x>{concat($nl,"===",$typeName,"===")}{
for $value in $type/xsd:restriction/xsd:enumeration/@value
let $enumName := string($value)
return concat($nl,"* ",$enumName)
}</x>
But if I try to remove the <x></x> it fails. I've tried every possible combination of {} and , imaginable. I also tried passing the second XQuery as an argument to concat() but that didn't work either. While I could do some post processing but since I'd like to be able to rely on XQuery in the future I want how to learn to do this the proper way.
I tried Googling but all examples show only the XML version and I'm certain there must be a way to do this for plain text
* Technically I'm trying to output it in MediaWiki syntax.
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Jun 13th, 2008, 03:26 AM
#2
Re: XQuery with Nested Return
The result of an XQuery is always an XML node. You will need to get your XML out and parse it to get the values you want in your 'client' language that deals with it - javascript, C#, PHP, whatever.
So the proper way is to get your node out and then parse it. XQuery isn't meant to be an XML processing/extraction language - think of it like SQL. You query rowsets in tables and you get rowsets out (even a single value is a rowset of one row, one column).
So you can do what you do currently
Code:
return <enumerations>{concat($nl,"===",$typeName,"===")}{
for $value in $type/xsd:restriction/xsd:enumeration/@value
let $enumName := string($value)
return concat($nl,"* ",$enumName)
}</enumerations>
Or you could do
Code:
<enumerations>
{
for $type in $src//xsd:simpleType[.//xsd:enumeration]
let $typeName := string($type/@name)
return {concat($nl,"===",$typeName,"===")}{
for $value in $type/xsd:restriction/xsd:enumeration/@value
let $enumName := string($value)
return concat($nl,"* ",$enumName)
}
}
</enumerations>
Not sure about the second example, I've typed it from memory of XQuery.
-
Jun 13th, 2008, 03:27 AM
#3
Re: XQuery with Nested Return
Out of curiosity, what XQuery parser/server do you use?
-
Jun 17th, 2008, 10:54 AM
#4
Thread Starter
Hyperactive Member
Re: XQuery with Nested Return
QExo
it was a small download and was easy to set up... and I am a Java developer.
Would you recommend something else?
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Jun 17th, 2008, 10:58 AM
#5
Thread Starter
Hyperactive Member
Re: XQuery with Nested Return
Hmm, just an idea, but would there be a way to return the result in the XML and then some how call on it? Don't have QExo infront of me right now or else I'd try it out; will do as soon as I get the chance
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Jun 17th, 2008, 12:48 PM
#6
Re: XQuery with Nested Return
No. Calling a 'text' method on it won't make sense. It is a list of nodes that you're getting back, not a single node. You will need to have a language that receives those nodes and extracts values out of it.
-
Jun 17th, 2008, 12:48 PM
#7
Re: XQuery with Nested Return
 Originally Posted by CaptainPinko
QExo
it was a small download and was easy to set up... and I am a Java developer.
Would you recommend something else?
In my experience, they've all been terrible. Each one worse than all the others, which is a statistical impossibility.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|