Results 1 to 7 of 7

Thread: XQuery with Nested Return

  1. #1

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Question 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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: XQuery with Nested Return

    Out of curiosity, what XQuery parser/server do you use?

  4. #4

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    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

  5. #5

    Thread Starter
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    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
    Code:
    text()
    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

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: XQuery with Nested Return

    Quote 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
  •  



Click Here to Expand Forum to Full Width