tags:

views:

397

answers:

2

I would like to know how to use the character "
" (LINE FEED) to separate some information in an attribute. Look the example below:

<element attrinfo="info1=109&#xA;info2=108&#xA;info3=107" />

I use SetAttribute() to set the attribute's text, but when the I save the XML, the information in attrinfo looks like that:

<element attrinfo="info1=109&amp;#xA;info2=108&amp;#xA;info3=107" />

The "&" is a special character, so the XML substitutes it by "&amp;"

How can I solve this? I saw something about use Entity Reference but I don't understand how to use it.

Here is my code using \n:

ls_DadosAdicionais = "volume=1800;peso=78;altura=157"
ll_pos = POS( ls_DadosAdicionais, ";" ) 
DO
    ls_DadosAdicionais = REPLACE( ls_DadosAdicionais, ll_pos, 1, '~n' )
    ll_pos = POS( ls_DadosAdicionais, ";", ll_pos + 1 )
LOOP WHILE ll_pos > 0
lo_exm = io_xml.createElement( "exame")
lo_exm.SetAttribute( "dados_adicionais", ls_DadosAdicionais )
+2  A: 

You should save the actual line feed character to the attribute. The escaping is taken care of by the API.

In other words: If you save the string "&#xA;", the API correctly escapes it as "&amp;#xA;", so that you get back the string "&#xA;" when you read the data again. Always store the data you want to store, never do any manual escaping.

Tomalak
+2  A: 

SetAttributes does the entity translation automatically. Don't substitute the newline manually. Just include the \n in the string you pass to SetAttribute. It should get translated to the proper entity when you save.

umilmi81
I included the \n in the string but didn´t work. When i open the xml in notepad++, i see the newline instead of the string "".
Notepad++ is too awesome to display the entity. It translates it back. Open in regular notepad.
umilmi81
I opened in regular notepad and it is the same. Look how it´s appearing:<exam code="TRIGL" info="volume=1800peso=78altura=157"/>
I opened in regular notepad and it is the same. Look how it´s appearing: <exam code="TRIGL" info="volume=1800 peso=78 altura=157"/>
sorry, it doesn´t work here, but it´s appearing in a new line each information of INFO´s attribute, not with spaces like is at my last comment.
Can you post your code?
umilmi81
ls_DadosAdicionais = "volume=1800;peso=78;altura=157"ll_pos = POS( ls_DadosAdicionais, ";" ) DO ls_DadosAdicionais = REPLACE( ls_DadosAdicionais, ll_pos, 1, '~n' ) ll_pos = POS( ls_DadosAdicionais, ";", ll_pos + 1 )LOOP WHILE ll_pos > 0lo_exm = io_xml.createElement( "exame")lo_exm.SetAttribute( "dados_adicionais", ls_DadosAdicionais )
ls_dados_adicionais="volume=1800;peso=78;altura=157" ll_pos =
i´ll try again, one line each time:ls_DadosAdicionais = "volume=1800;peso=78;altura=157"
ll_pos = POS( ls_DadosAdicionais, ";" )
i put the code in my question.
@Thaisa: Can you delete all these comments now that you've posted the code in your question? Thanks. :)
Tomalak
i already tried, but when i click in the delete button, appears a red box with the message "you cannot vote for this comment", and the comment is not deleted. Do you know why it happens?
@Thaisa: The delete button is a small gey "x" at the end of your comment (appears on mouseover). The arrow you clicked on is for voting on comments - it even says "vote this as a great comment" in the tool tip ;-).
Tomalak