Also keep in mind that there's already some XML functionality provided
by the XML script service, accessible in Velocity using $services.xml
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-xml/xwiki-platform-xml-script/src/main/java/org/xwiki/xml/internal/XMLScriptService.java
On 03/24/2012 03:33 PM, du du wrote:
Oh, it is working now, thanks very much for your help.
On Sat, Mar 24, 2012 at 12:28 PM, Sergiu Dumitriu<[email protected]> wrote:
On 03/24/2012 12:00 PM, du du wrote:
Hi, Sergiu Dumitriu
I tried your way like this:
{{velocity output='false'}}
$response.setContentType('**application/xml')
#set ($out = $response.getOutputStream())
#set ($s = "<?xml version='1.0' encoding='ISO-8859-1'?><test>**test
done</test>")
$out.write($s.getBytes('ISO-**8859-1'))
{{/velocity}}
But this still has the same parsing error:
XML Parsing Error: no element found
Location:
http://localhost:8080/xwikim/**bin/get/Geo/hellotest?**outputSyntax=plain<http://localhost:8080/xwikim/bin/get/Geo/hellotest?outputSyntax=plain>
Line Number 1, Column 1:
^
I tried both from the ajax call and the link:
http://localhost:8080/xwikim/**bin/get/Main/hellotest?**
outputSyntax=plain<http://localhost:8080/xwikim/bin/get/Main/hellotest?outputSyntax=plain>
and I got the same error.
Any more clue?
Yes, you should leave the flush and close calls as well, since the stream
isn't automatically closed.
Thanks for your help.
Dave
On Sat, Mar 24, 2012 at 10:41 AM, Sergiu Dumitriu<[email protected]>
wrote:
On 03/24/2012 09:33 AM, du du wrote:
Hi, Thomas,
Thanks for your response, I changed to this url:
http://localhost:8080/xwikim/****bin/get/Main/hellotest?**<http://localhost:8080/xwikim/**bin/get/Main/hellotest?**>
outputSyntax=plain<http://**localhost:8080/xwikim/bin/get/**
Main/hellotest?outputSyntax=**plain<http://localhost:8080/xwikim/bin/get/Main/hellotest?outputSyntax=plain>
But I got responseXML containing this error:
XML Parsing Error: no element found Location:
http://localhost:8080/xwikim/****bin/get/Main/hellotest?**<http://localhost:8080/xwikim/**bin/get/Main/hellotest?**>
outputSyntax=plain<http://**localhost:8080/xwikim/bin/get/**
Main/hellotest?outputSyntax=**plain<http://localhost:8080/xwikim/bin/get/Main/hellotest?outputSyntax=plain>
Line
Number 1, Column 1:
then I changed to this velocity code:
{{velocity output='false'}}
$response.setContentType('****application/xml')
#set ($out = $response.getOutputStream())
$out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>****test
done</test>")
$out is an OutputStream, which doesn't have a write(String) method. You
must give it a byte[] argument, so this works:
#set ($s = "<?xml version='1.0' encoding='ISO-8859-1'?><test>****test
done</test>")
$out.write($s.getBytes('ISO-****8859-1'))
$out.flush()
##$out.close()
{{/velocity}}
Still the same parsing error, any clue?
Thanks
Dave
On Sat, Mar 24, 2012 at 4:38 AM, Thomas Mortagne
<[email protected]>****wrote:
On Sat, Mar 24, 2012 at 3:23 AM, du du<[email protected]> wrote:
Hi, all,
I followed this link:
http://platform.xwiki.org/****xwiki/bin/DevGuide/****
WritingComponents<http://platform.xwiki.org/**xwiki/bin/DevGuide/**WritingComponents>
<http://**platform.xwiki.org/xwiki/bin/**DevGuide/WritingComponents<http://platform.xwiki.org/xwiki/bin/DevGuide/WritingComponents>
created a component which return xml data.
Also I created a hellotest page inside the main space, and wrote the
following velocity code:
{{velocity output='false'}}
$response.setContentType('****application/xml')
#set ($xmldata= $services.hello.getHelloXML())
$xmldata
##$context.setFinished(true)
#set ($out = $response.getOutputStream())
$out.write($xmldata)
$out.flush()
{{/velocity}}
I tested this code, I can get the xml data, now I use this ajax code
to
retrieve the xml data:
var xmlhttp = GetXmlHttp();
if (xmlhttp) {
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
xmlResult = xmlhttp.responseText;
......
xmlhttp.send(null);
}
The url I used is:
url = '
http://localhost:8080/xwikim/****bin/view/Main/hellotest?**<http://localhost:8080/xwikim/**bin/view/Main/hellotest?**>
outputSyntax=plain<http://**localhost:8080/xwikim/bin/**
view/Main/hellotest?**outputSyntax=plain<http://localhost:8080/xwikim/bin/view/Main/hellotest?outputSyntax=plain>
'
when I debug with firefox to see the data inside xmlhttp either
responseText or response, they were all a html document for the
hellotest
with the tags like body, div, etc, it is basically helltest.html file
if
you view the source code of this html page. I tried to change the
output
to
true, the result is the same.
That's because with this URL you get UI around your content (whatever
is the syntax of your content), for this kind of use case you should
use /get/ action instead of /view/.
Question: how can I get the xml data? where am I wrong?
Thanks very much in advance.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users