Sending XML containing html tags

View: New views
4 Messages — Rating Filter:   Alert me  

Sending XML containing html tags

by Rafael Escote :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear folks, i'm trying to build a correct AJAX (using RICO js libs)
response from 4D, so i'm building an
XML document using the DOM commands and sending it via
SEND HTML BLOB.
However I've found that if the response text includes
some tags to format the html page
the result is not the one desired. For example:

// Test response
$answer:="<span>Testing</span>"

$myxml:=DOM Create XML Ref("ajax-response")

DOM SET XML OPTIONS($myxml;"ISO-8859-1")

$elem:=DOM Create XML element($myxml;"/ajax-response/
response";"type";"element";"id";"myObject")

DOM SET XML ELEMENT VALUE($elem;$answer)
DOM EXPORT TO VAR($myxml;$result)
DOM CLOSE XML($myxml)
...
SEND HTML BLOB($result;"text/xml")

The sent text is always translating the tag <span> into
somthing like:
<span>Pepe</span>

Being an XML, BLOB ignorant I'm not sure what i'm doing wrong...
Any help?
TIA
--
Rafael Escoté
BlauSoft s.l.


**********************************************************************
The 4D v11 SQL Roadshow - coming to a city near you!
http://www.4D.com/roadshow/index.html

4th Dimension Internet Users Group (4D iNUG)
FAQ:  http://www.4d.com/support/faqnug.html
Archive:  http://dir.gmane.org/gmane.comp.lang.inug-4d.tech
Unsub:  mailto:4D_Tech-Unsubscribe@...
Post: mailto:4d_tech@...
Options: https://lists.4d.com/mailman/listinfo/4d_tech
**********************************************************************

Re: Sending XML containing html tags

by David Dancy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Rafael

I think that DOM SET XML ELEMENT VALUE is translating the < into <
for you. There's not much you can do about that, because what you're
sending is itself XML.

However, it ought to be possible within javascript (in your method
that accepts the data coming back from the Rico Ajax object) to parse
for < and > (use a regex) and turn them back to < and >
respectively. Then you have to set the .innerHTML (I think) property
of a DOM object in the web page to the value you've been given, and I
think that will work. It's a bit harder, but I think that's necessary
in order to be able to send XML inside XML.

If it's easier, you could use DOM SET XML ELEMENT
VALUE($elem;$answer;*) which puts the $answer text into the CDATA
section of the XML. That might be easier to parse once it gets to the
web page.

An alternative is to set the <span> tag in your HTML with no contents,
give it an ID, and then send back the contents of the span only, then
use javascript to fill in the contents of the span from the result of
the Ajax call. Given the choice, this is the way I'd do it, but I'm
only just learning, so others may have better ideas.

David
**********************************************************************
The 4D v11 SQL Roadshow - coming to a city near you!
http://www.4D.com/roadshow/index.html

4th Dimension Internet Users Group (4D iNUG)
FAQ:  http://www.4d.com/support/faqnug.html
Archive:  http://dir.gmane.org/gmane.comp.lang.inug-4d.tech
Unsub:  mailto:4D_Tech-Unsubscribe@...
Post: mailto:4d_tech@...
Options: https://lists.4d.com/mailman/listinfo/4d_tech
**********************************************************************

Re: Sending XML containing html tags

by Julio Carneiro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Rafael,
That is exactly what it is supposed to do.
XML has very strict rules about the characters that can be used for  
element names and element values.
Some characters albeit not permitted inside element values can be  
translated into character encoded sequences (<, >, &).
Other are not even allowed: accented chars for example.
XML does provide a mean to send element values that contain invalid  
characters unencoded. That is done via a CDATA element value.

In 4D you do that by adding a '*' as a 3rd parameter to DOM SET  
ELEMENT VALUE, as in:
> DOM SET XML ELEMENT VALUE($elem;$answer;*)

Javascript xml tools handle CDATA sections properly and you should not  
have to do anything special on AJAX side.
Adding the '*' as above should do the trick.

hth
julio

On May 13, 2008, at 12:34 PM, Rafael Escote wrote:

> Dear folks, i'm trying to build a correct AJAX (using RICO js libs)
> response from 4D, so i'm building an
> XML document using the DOM commands and sending it via
> SEND HTML BLOB.
> However I've found that if the response text includes
> some tags to format the html page
> the result is not the one desired. For example:
>
> // Test response
> $answer:="<span>Testing</span>"
>
> $myxml:=DOM Create XML Ref("ajax-response")
>
> DOM SET XML OPTIONS($myxml;"ISO-8859-1")
>
> $elem:=DOM Create XML element($myxml;"/ajax-response/
> response";"type";"element";"id";"myObject")
>
> DOM SET XML ELEMENT VALUE($elem;$answer)
> DOM EXPORT TO VAR($myxml;$result)
> DOM CLOSE XML($myxml)
> ...
> SEND HTML BLOB($result;"text/xml")
>
> The sent text is always translating the tag <span> into
> somthing like:
> <span>Pepe</span>
>
> Being an XML, BLOB ignorant I'm not sure what i'm doing wrong...
> Any help?
> TIA
> --
> Rafael Escoté
> BlauSoft s.l.
>

**********************************************************************
The 4D v11 SQL Roadshow - coming to a city near you!
http://www.4D.com/roadshow/index.html

4th Dimension Internet Users Group (4D iNUG)
FAQ:  http://www.4d.com/support/faqnug.html
Archive:  http://dir.gmane.org/gmane.comp.lang.inug-4d.tech
Unsub:  mailto:4D_Tech-Unsubscribe@...
Post: mailto:4d_tech@...
Options: https://lists.4d.com/mailman/listinfo/4d_tech
**********************************************************************

Re: Sending XML containing html tags

by MIYAKO :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

the whole point of xml is that it contains data elements only,
as opposed to conventional html which has data and style.

XSLT is supposed to be the solution to convert xml into html.

alternatively, you could create small methods (method name "span", for  
example),
to be called within the context of constructing the xml,
which given a DOM reference and value would insert a span tag.

but, yes, there are cases where you would like to insert a piece of xml
within a parent xml, which seems to be beyond the capabilities of DOM  
commands.

incidentally the SAX ADD XML ELEMENT VALUE has been enhanced in v11 to
accept an * to directly handle escape characters.

miyako

On 2008/05/14, at 0:34, Rafael Escote wrote:

> Dear folks, i'm trying to build a correct AJAX (using RICO js libs)
> response from 4D, so i'm building an
> XML document using the DOM commands and sending it via
> SEND HTML BLOB.
> However I've found that if the response text includes
> some tags to format the html page
> the result is not the one desired. For example:
>
> // Test response
> $answer:="<span>Testing</span>"
>
> $myxml:=DOM Create XML Ref("ajax-response")
>
> DOM SET XML OPTIONS($myxml;"ISO-8859-1")
>
> $elem:=DOM Create XML element($myxml;"/ajax-response/
> response";"type";"element";"id";"myObject")
>
> DOM SET XML ELEMENT VALUE($elem;$answer)
> DOM EXPORT TO VAR($myxml;$result)
> DOM CLOSE XML($myxml)
> ...
> SEND HTML BLOB($result;"text/xml")
>
> The sent text is always translating the tag <span> into
> somthing like:
> <span>Pepe</span>
>
> Being an XML, BLOB ignorant I'm not sure what i'm doing wrong...
> Any help?
> TIA
> --
> Rafael Escoté
> BlauSoft s.l.

**********************************************************************
The 4D v11 SQL Roadshow - coming to a city near you!
http://www.4D.com/roadshow/index.html

4th Dimension Internet Users Group (4D iNUG)
FAQ:  http://www.4d.com/support/faqnug.html
Archive:  http://dir.gmane.org/gmane.comp.lang.inug-4d.tech
Unsub:  mailto:4D_Tech-Unsubscribe@...
Post: mailto:4d_tech@...
Options: https://lists.4d.com/mailman/listinfo/4d_tech
**********************************************************************