Call to Java function returning XML content.
Added by Anonymous over 17 years ago
Legacy ID: #4224242 Legacy Poster: popol (mrjeje)
Hello, I post a second message since this concerns a new problem I have. I still use an external Java function that returns an XML formatted string. My query <root> { let $title := if(doc('AMM_chapter_05')/AMM/TITLE) then doc('AMM_chapter_05')/AMM/TITLE/text() else "AMM" let $link := linkToDocument:generate(util:nullParam(), 'amm', "doc('AMM_chapter_05')/AMM", util:nullParam(), 'amm', util:nullParam(), util:nullParam()) let $item := tocItem:generate('/', 'test', fn:false(), util:nullParam(), $link) return saxon:serialize(saxon:parse(string($item)), <xsl:output method="html" omit-xml-declaration="yes" indent="yes" saxon:indent-spaces="1"/>) } </toc-items> When I retrieve the result string after the query execution, all '<' and '>' characters are escaped.
Replies (4)
Please register to reply
RE: Call to Java function returning XML conte - Added by Anonymous over 17 years ago
Legacy ID: #4224432 Legacy Poster: Michael Kay (mhkay)
I'm confused by your query. Does it really start with the four characters (& l t ;) or does it really start with the character "<"? Because as far as I can see, a query starting with "&" would be a syntax error. So I'll assume it's really <root>. As for the substance of your question, it then depends on what the function tocItem:generate() returns. You haven't shown me the function or provided any information about its output, so I can't offer much. But the fact that there's some funny escaping of the query in your message makes me suspect oddities in the escaping elsewhere.
RE: Call to Java function returning XML conte - Added by Anonymous over 17 years ago
Legacy ID: #4227469 Legacy Poster: popol (mrjeje)
Hello, Sorry, I sped up because I got to go pick up my daughter... ;-) The "<" is because this query is in an XML settings file. Ok now I read my question, I see that I have not been explicit enough (and by far). I execute the following (simplified) request: declare namespace test:"java:Test"; <root> { let $item := test:generate() return $item } </root> where the 'generate()' method returns an XML formatted string like : public static generate(){ return "<test>content</test>"; } When I execute this request in 'xml' output mode, I get the following result: <root> <test>content<test> </root> When I execute this request in 'text' output mode, I get the following result: <test>content</test> but the enclosing 'root' tag seems to have disappear. Note that I found a way to have a valid result using the following query in 'text' output mode: let $item := test:generate() return concat("<root>",$item, "</root>") It works but though in my case it is really simple, sometimes in my application, the enclosing XML is not simple as "<root>" and the queries becomes unreadable and difficult to maintain.
RE: Call to Java function returning XML conte - Added by Anonymous over 17 years ago
Legacy ID: #4227473 Legacy Poster: popol (mrjeje)
Hello, Sorry, I sped up because I got to go pick up my daughter... ;-) The "<" is because this query is in an XML settings file. Ok now I read my question, I see that I have not been explicit enough (and by far). I execute the following (simplified) request: declare namespace test:"java:Test"; <root> { let $item := test:generate() return $item } </root> where the 'generate()' method returns an XML formatted string like : public static generate(){ return "<test>content</test>"; } When I execute this request in 'xml' output mode, I get the following result: <root> <test>content<test> </root> When I execute this request in 'text' output mode, I get the following result: <test>content</test> but the enclosing 'root' tag seems to have disappear. Note that I found a way to have a valid result using the following query in 'text' output mode: let $item := test:generate() return concat("<root>", $item, "</root>") It works but though in this case it is really simple, sometimes in my application, the enclosing XML is not simple as "<root>" and I found that the queries becomes unreadable and difficult to maintain. Hope this is clearer. Thanks in advance, Jérôme.
RE: Call to Java function returning XML conte - Added by Anonymous over 17 years ago
Legacy ID: #4227485 Legacy Poster: Michael Kay (mhkay)
I wouldn't advise using the text output method if your query result is actually XML, because that means in effect that you have to take responsibility for serializing it yourself, which is potentially a lot of work. Although you could use the saxon:serialize() function to offload much of the work, of course. In your example, the fact that the start and end tags for "root" have disappeared is part of the specification of the text output method: this method outputs the string value of the tree you have constructed, that is, the concatenation of its text nodes. As I explained in my earlier response, if you want an external function to return XML then you must parse the lexical XML into a tree either before returning it from the function (for example by calling Configuration#buildDocument()), or after returning it (by calling saxon:parse()). It's best to stick entirely to processing XML in the form of trees, and use the lexical angle-bracket representation of XML only at the boundaries of the system.
Please register to reply