Hi, first the code I gave you is for creating new xml content, if you're
reading from a file, you don't need it. If you were already able to retreive
your text but it was only the formating part that was missing, you only need
to put the CDATA section in your XML. CDATA are read the same way as text
node.

I'll explain anyway what my code do and why like you asked.

These are constant, it's only best pratice to replace all plain text in your
code by constant:
PRODUCTTAG = "product"
PRODUCTUIDTAG = "productUID"

I used this example to show the difference between creating a normal text
node by doing so :
Text productUIDText = xml.createTextNode(*this*.productUID);

and creating a CDATA text node by doing this:
Text productDescriptionText =
xml.createCDATASection(this.productDescription);

You can read both of these node by doing so :
this.productUID =
objectElement.getElementsByTagName("productUID").item(0).getFirstChild().getNodeValue();
this.productDescription =
objectElement.getElementsByTagName("productDescription").item(0).getFirstChild().getNodeValue();

objectElement would be one product.
For you, object element would be your page element. But it should'nt be a
problem if you already retrived all content element to do
contents.item(0).getFirstChild().getNodeValue();

HAHA oh I forgot to put my constant in this one ! LOL
I hope it's fnally clearer :)

Christian
On Thu, Aug 6, 2009 at 8:11 AM, Nickelnext <[email protected]> wrote:

>
> first, thank you for your help.
>
> Second: I read your answers and I understand that I need to put my
> text in CDATA sections.
> What I don't understand is why I need to to this
>
> Element product = xml.createElement(*PRODUCTTAG*);
> Element productUID = xml.createElement(*PRODUCTUIDTAG*);
> Text productUIDText = xml.createTextNode(*this*.productUID);
> productUID.appendChild(productUIDText);
> product.appendChild(productUID);
> products.appendChild(product);
>
> first: - can you explain what are your constants (PRODUCTTAG,
> PRODUCTUIDTG) about? It will help me understand better your example.
> Thanks
> second: - should i create a TextNode or a CDATA node like you wrote
> before, to read text between cdata tags?
> third : - what you do is to create a TextNode with "content" tag,
> right? Then you append this node somewhere in the Document, then you
> get it back with contents = element.getElementsByTagName("content"); ,
> right?
>
> Answering your question: contents is a collection, cause the
> getElementsByTagName("content") returns all the nodes that have
> "content" tag, so I use item(x) to retrieve the item x in that
> collection.
>
> Besides, my xml is like that,
> <pages>
>  <page>
>    <content>first text here</content>
>  </page>
>  <page>
>    <content>second text here</content>
>  </page>
> </pages>
>
>
> So i need to create a text element for EACH item in that collection,
> right?
>
> Sorry for my dumb questions but i can't really figure out what is the
> right solution for my problem, thank you again for your time.
>
> Bye
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to