Quantcast

html markup escape and CDATA issue

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

html markup escape and CDATA issue

FOX427
Hi All! I am fetching data from xml as usual, I have a node ${document.details.location} and it might have  html markup in it, so for example in one xml the node is empty and in another it has a lot of markup like:

<location>
<p>Some Hotel Name <br /> Some Street<br /> Miami, FL 33131<br /> 305 503 5555 </p>.
</location>

The problem is, if I use <#escape x as x?html> and put ${document.details.location} in it the it will give me:

<p>Some Hotel Name <br /> Some Street<br /> Miami, FL 33131<br /> 305 503 5555 </p>.(including <br> <p> and etc. in the browser )


If I generate xml and wrap that node in CDATA like here:
<location>
<![CDATA[ <p><a href="www.google.com" target="_blank">Some Hotel Name</a>&#160;<br /> Some Street<br /> Miami, FL 33131<br /> 305 503 5555 </p>. ]]>
 
</location>

then I have:

Some Hotel Name
Some Street
Miami, FL 33131
305 503 5555
]]>

So the issue here I am getting "]]> " out of nowhere....Can someone explain what is best practice in handling random html markup nodes so i can be safe. Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: html markup escape and CDATA issue

Daniel Dekany
I don't understand what you trying to say. If you don't want to escape
the output, then why are you using #escalpe (or why don't you use
#noescape)? Where do you put that CDATA section and how?


Tuesday, March 3, 2015, 9:31:22 PM, FOX427 wrote:

> Hi All! I am fetching data from xml as usual, I have a node
> ${document.details.location} and it might have  html markup in it, so for
> example in one xml the node is empty and in another it has a lot of markup
> like:
>
> <location>
> <p> Some Hotel Name <www.google.com>  &#160;<br /> Some Street<br /> Miami,
> FL 33131<br /> 305 503 5555 </p>.
> </location>
>
> The problem is, if I use <#escape x as x?html> and put
> ${document.details.location} in it the it will give me:
>
> <p> Some Hotel Name <www.google.com>  &#160;<br /> Some Street<br /> Miami,
> FL 33131<br /> 305 503 5555 </p>.(including <br> <p> and etc. in the browser
> )
>
>
> If I generate xml and wrap that node in CDATA like here:
> <location>
>  
> </location>
>
> then I have:
>
> Some Hotel Name
> Some Street
> Miami, FL 33131
> 305 503 5555
]]>>

>
> So the issue here I am getting "*]]>* " out of nowhere....Can someone
> explain what is best practice in handling random html markup nodes so i can
> be safe. Thanks in advance.
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/html-markup-escape-and-CDATA-issue-tp4655387.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: html markup escape and CDATA issue

FOX427
Ok, when you have xml with this node:

<location> 
 <p> Some Hotel Name    <br /> Some Street<br /> Miami,
 FL 33131<br /> 305 503 5555 </p>.
</location> 

in order to get value from it I have to use:

<#list document.details.location as loc>
        <#if loc.p??&&loc.p?has_content>
                <#list loc.p as p>
                        <#if p.a??&&p.a?has_content>
                                <a href="${p.a.@href}">${p.a}
                        </#if>
                        <#list p?children as nodes>
                                ${nodes}
                        </#list>
                </#list>
        </#if>
</#list>

and all these lines will be for nothing if next xml has two "<p></p>" or no "<p></p>" at all or completely different things in node, i dont know why but freemarker treats <p> as child node, as a result, if node has <p> and you dont use ${p.xxxx} it complains saying it has child node, and vice versa, if you add ${p.xxxx} and there is no <p> it prints nothing. So my main goal is to be able to use freemarker that handles html markups in prompt way so I don't have to worry about having different html markups in different xml with the same node name(<location>).

So i thought maybe I need to use escape or CDATA to get rid of this issue...I am just starting to learn freemarker, maybe i don't understand a lot of stuff that might be very basic for you so i apologize in advance :( Thank you. :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: html markup escape and CDATA issue

Daniel Dekany
Tuesday, March 3, 2015, 10:51:08 PM, FOX427 wrote:

> Ok, when you have xml with this node:
>
> <location>
>  <p>  Some Hotel Name    &#160;<br /> Some Street<br /> Miami,
>  FL 33131<br /> 305 503 5555 </p>.
> </location>
>
> in order to get value from it I have to use:
>
> <#list document.details.location as loc>
>         <#if loc.p??&&loc.p?has_content>

(`loc.p??` is always true - see XML Processing Guide)

>                 <#list loc.p as p>
>                         <#if p.a??&&p.a?has_content>

(`loc.a??` is always true too)

>                                  ${p.a} <${p.a.@href}>

Are you sure there are never multiple `p.a`-s?

>                         </#if>
>                         <#list p?children as nodes>
>                                 ${nodes}
>                         </#list>
>                 </#list>
>         </#if>
> </#list>

(There was no #escape here BTW.)

> and all these lines will be for nothing if next xml has two "<p></p>" or no
> "<p></p>" at all or completely different things in node, i dont know why but
> freemarker treats <p> as child node, as a result, if node has <p> and you
> dont use ${p.xxxx} it complains saying it has child node, and vice versa, if
> you add ${p.xxxx} and there is no <p> it prints nothing. So my main goal is
> to be able to use freemarker that handles html markups in prompt way so I
> don't have to worry about having different html markups in different xml
> with the same node name(<location>).

Sorry, I don't really understand what you are saying, but if you just
want to print everything inside <location>...</location>, then use
${location.@@nested_markup}. (Inside #noescape if you are inside
#escape.)

Or, the contents of <location> should be CDATA, inside the XML. Now of
course it's up to the designers of the XML schema, and I don't know
what their design goals were.

> So i thought maybe I need to use escape or CDATA to get rid of this
> issue...I am just starting to learn freemarker, maybe i don't understand a
> lot of stuff that might be very basic for you so i apologize in advance :(

Read the XML Processing Guide of you haven't. You can spare a lot of
time of yours with that.

> Thank you. :)

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: html markup escape and CDATA issue

FOX427
Thanks Daniel,

@@nested_markup - that's what i need! But I used @@markup before it worked perfectly fine if node has a lot of markups but failed to show result if node had a string(<location>Mars</location>) so even node has string value it treats it as empty node?

Also, I would like to know what do you think about including html inside XML? Do you think it is a good idea? If its bad then what would you suggest? Thanks again
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: html markup escape and CDATA issue

Daniel Dekany
Wednesday, March 4, 2015, 8:11:38 PM, FOX427 wrote:

> Thanks Daniel,
>
> @@nested_markup - that's what i need! But I used @@markup before it worked
> perfectly fine if node has a lot of markups but failed to show result if
> node had a string(<location>Mars</location>) so even node has string value
> it treats it as empty node?

You have overlooked something there... If you go to
http://freemarker-online.kenshoo.com/ and copy-paste this into the
template field:

  Nested markup: ${doc.location.@@nested_markup}
  Markup: ${doc.location.@@markup}

and this to the data-model field:

  doc=<location>Marsh</location>

then output will be:

  Nested markup: Marsh
  Markup: <location>Marsh</location>

> Also, I would like to know what do you think about including html inside
> XML? Do you think it is a good idea? If its bad then what would you suggest?

If you won't parse that HTML content then store it in the XML as
non-XML character data. Like inside a CDATA section, or just escaped.
Especially as HTML is not always well-formed XML. Then you don't need
@@markup and such either. It's much faster to load and output the
content then.

> Thanks again
>
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/html-markup-escape-and-CDATA-issue-tp4655387p4655391.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...