Login  Register

XMLReader problem

classic Classic list List threaded Threaded
4 messages Options Options
Embed post
Permalink
hcr
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

XMLReader problem

hcr
103 posts
Hi,
    In OPS, I want to process a Document using XMLReader. But CDATA is lose. For example:

    public static void main(String[] args) throws SAXException, IOException{
        Document outData = DocumentHelper.createDocument();
        Element root = outData.addElement("root");
        root.addElement("script").addCDATA("HELLO");
        root.addElement("head").addText(" world");

        SAXStore store = new SAXStore();
        final XMLReader xmlReader = XMLUtils.newSAXParser().getXMLReader();
        xmlReader.setContentHandler(store);
        xmlReader.parse(new DocumentSource(outData).getInputSource());
        System.o ut.println(Dom4jUtils.domToString(store.getDocument()));
    }

The output is that:
<root>
    <script>HELLO</script>
    <head>world</head>
</root>

I want to output:
<root>
    <script><![CDATA[HELLO]]></script>
    <head>world</head>
</root>
       






--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: XMLReader problem

Alessandro  Vernet
Administrator
5128 posts
Yes, this is because this information is part of the SAX LexicalHandler, which we don't support. But note that the CDATA markers are just syntactic sugar, and a document without them should be considered equivalent.

(BTW, I am not sure what happened, but I got your message 8 times through the mailing list.)

Alex



On Jan 19, 2010, at 5:57 PM, hechengrong <[hidden email]> wrote:

Hi,
    In OPS, I want to process a Document using XMLReader. But CDATA is lose. For example:

    public static void main(String[] args) throws SAXException, IOException{
        Document outData = DocumentHelper.createDocument();
        Element root = outData.addElement("root");
        root.addElement("script").addCDATA("HELLO");
        root.addElement("head").addText(" world");

        SAXStore store = new SAXStore();
        final XMLReader xmlReader = XMLUtils.newSAXParser().getXMLReader();
        xmlReader.setContentHandler(store);
        xmlReader.parse(new DocumentSource(outData).getInputSource());
        System.o ut.println(Dom4jUtils.domToString(store.getDocument()));
    }

The output is that:
<root>
    <script>HELLO</script>
    <head>world</head>
</root>

I want to output:
<root>
    <script><![CDATA[HELLO]]></script>
    <head>world</head>
</root>
       





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
OW2 mailing lists service home page: http://www.ow2.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
hcr
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Re: XMLReader problem

hcr
103 posts

It is error In My example. For example:

1. My view.xhtml like that:

    ...

         <xhtml:script>

               <![CDATA[

                       //this is comment

                       function hello(){

                         ........

                        }

                ]]>

         </xhtml:script>

    ...

2. I serilizered xformed-data, the file content like that:

...

    <xhtml:script><![CDATA[//this is comment function hello(){ ... }]]></xhtml:script>
....

3. load serilizered file to http, It is error. error message is "not found hello function" 

 


在2010-01-20 11:11:12,"Alessandro Vernet" <[hidden email]> 写道:

Yes, this is because this information is part of the SAX LexicalHandler, which we don't support. But note that the CDATA markers are just syntactic sugar, and a document without them should be considered equivalent.

(BTW, I am not sure what happened, but I got your message 8 times through the mailing list.)

Alex



On Jan 19, 2010, at 5:57 PM, hechengrong <[hidden email]> wrote:

Hi,
    In OPS, I want to process a Document using XMLReader. But CDATA is lose. For example:

    public static void main(String[] args) throws SAXException, IOException{
        Document outData = DocumentHelper.createDocument();
        Element root = outData.addElement("root");
        root.addElement("script").addCDATA("HELLO");
        root.addElement("head").addText(" world");

        SAXStore store = new SAXStore();
        final XMLReader xmlReader = XMLUtils.newSAXParser().getXMLReader();
        xmlReader.setContentHandler(store);
        xmlReader.parse(new DocumentSource(outData).getInputSource());
        System.o ut.println(Dom4jUtils.domToString(store.getDocument()));
    }

The output is that:
<root>
    <script>HELLO</script>
    <head>world</head>
</root>

I want to output:
<root>
    <script><![CDATA[HELLO]]></script>
    <head>world</head>
</root>
       





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: [hidden email]
OW2 mailing lists service home page: http://www.ow2.org/wws




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Re: Re: XMLReader problem

Alessandro  Vernet
Administrator
5128 posts
I see. So you are saying that some newlines are lost. How do you
process the file? Can you provide us with some code we can run here to
reproduce this?

Alex

2010/1/19 hechengrong <[hidden email]>:

> It is error In My example. For example:
>
> 1. My view.xhtml like that:
>
>     ...
>
>          <xhtml:script>
>
>                <![CDATA[
>
>                        //this is comment
>
>                        function hello(){
>
>                          ........
>
>                         }
>
>                 ]]>
>
>          </xhtml:script>
>
>     ...
>
> 2. I serilizered xformed-data, the file content like that:
>
> ...
>
>     <xhtml:script><![CDATA[//this is comment function hello(){ ...
> }]]></xhtml:script>
> ....
>
> 3. load serilizered file to http, It is error. error message is "not found
> hello function"
>
>
>
> 在2010-01-20 11:11:12,"Alessandro Vernet" <[hidden email]> 写道:
>
> Yes, this is because this information is part of the SAX LexicalHandler,
> which we don't support. But note that the CDATA markers are just syntactic
> sugar, and a document without them should be considered equivalent.
> (BTW, I am not sure what happened, but I got your message 8 times through
> the mailing list.)
> Alex
>
>
> On Jan 19, 2010, at 5:57 PM, hechengrong <[hidden email]> wrote:
>
> Hi,
>     In OPS, I want to process a Document using XMLReader. But CDATA is lose.
> For example:
>
>     public static void main(String[] args) throws SAXException, IOException{
>         Document outData = DocumentHelper.createDocument();
>         Element root = outData.addElement("root");
>         root.addElement("script").addCDATA("HELLO");
>         root.addElement("head").addText(" world");
>
>         SAXStore store = new SAXStore();
>         final XMLReader xmlReader = XMLUtils.newSAXParser().getXMLReader();
>         xmlReader.setContentHandler(store);
>         xmlReader.parse(new DocumentSource(outData).getInputSource());
>         System.o ut.println(Dom4jUtils.domToString(store.getDocument()));
>     }
>
> The output is that:
> <root>
>     <script>HELLO</script>
>     <head>world</head>
> </root>
>
> I want to output:
> <root>
>     <script><![CDATA[HELLO]]></script>
>     <head>world</head>
> </root>
>
>
>
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing
> list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing
> list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
My Twitter: http://twitter.com/avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet