Thank definitely did the trick however it affects the entire query. The query should output xml of the api call requests. I tried adding serialization parameters to the single fn:serialize method and set the output to 'text' however now it only returns the 'text' inside of the elements and not the xml. The script as a whole is supposed to return xml with results. The only json part is for the API calls. Here is a more full script:
declare option db:parser "html";
declare option db:htmlopt "html=true";
declare variable $js := '{';
declare variable $je := '}';
let $serializationParameters :=
<output:serialization-parameters
xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
xmlns="http://example.org/ext">
<output:method value="text"/>
<results>
for $productInfo in doc("http://www.someUrl.com/support/versions.shtml")//div[@id='contenedor']/div[@id] return
let $request :=
<http:request href='http://www.someExternalService.com/api/core/v3/contents'
method='post' username='admin' password='admin' send-authorization='true'>
<http:body media-type="application/json">
{json:serialize(
<json objects="json">
<subject>$productInfo/name</subject>
<content type="object">
<type>text/html</type>
<text>{fn:serialize($productInfo/* , $serializationParameters )}</text>
</content>
<type>document</type>
</json> )}
</http:body>
</http:request> return
<result>
try {http:send-request($request)[2]}
catch HC0001 {'Not Found'}
</result>
</results>
I guess I would expect this to operate as you described since I set the output:method to 'text'. Let me know if you have any ideas? I have read that serialization page several times and I guess I'm just not understanding this piece.
Thanks again.
- James
> From: christian.gruen@gmail.com
> Date: Fri, 2 Aug 2013 09:28:48 +0200
> Subject: Re: [basex-talk] Question around JSON Serialization
> To: james.jw@hotmail.com
> CC: basex-talk@mailman.uni-konstanz.de
>
> Hi James,
>
> by default, all string results are XML-encoded. You’ll get the
> expected result by declaring "text" as output option in the prolog
> (header) of your query:
>
> declare option output:method 'text';
> let $someItem := ...
>
> Our Wiki page on serialization may give you more hints [1].
>
> Hope this helps,
> Christian
>
> [1] http://docs.basex.org/wiki/Serialization
> ___________________________
>
> 2013/8/2 James Wright <james.jw@hotmail.com>:
> > Hey BaseX Team,
> >
> > Im trying to serialize some JSON in order to make a few calls to an external
> > api. In the json I need to include 'html' for example:
> >
> > {
> > "subject": "Test Subject",
> > "content": {
> > type: "text/html",
> > text: "<div><h2>Issue:</h2></div>
> > },
> > "type": "document"
> > }
> >
> > When I call the following script however I get:
> >
> > {
> > "subject": "Test Subject 10",
> > "content": {
> > "type": "text\/html",
> > "text": "<html>\n <div>\n <h2>Issue:<\/h2>\n
> > <\/div>\n<\/html>"
> > },
> > "type": "document"
> > }
> >
> > I tried messing with the serialization parameters however with no success. I
> > use the resulting string as the content for a http post request. Any help
> > would be appreciated.
> >
> > Script:
> > let $htmlContent := <div><h2>Issue:</h2></div>
> > return json:serialize(
> > <json objects="json">
> > <subject>Test Subject 10</subject>
> > <content type="object">
> > <type>text/html</type>
> > <text>{fn:serialize(<html>{ $someItem }</html>)}</text>
> > </content>
> > <type>document</type>
> > </json> )
> >
> > Thanks,
> > James
> >
> > _______________________________________________
> > BaseX-Talk mailing list
> > BaseX-Talk@mailman.uni-konstanz.de
> > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
> >