Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
johnsonted
Visitor

XML Format Issue

My channel reads from an XML file to get info on my videos. The XML content is formatted so that special XML characters get escaped.

For example, in the XML file where there is a " character this is escaped as &quot; and < turns into &lt; etc . Just the standard stuff for XML content.

The issue I have is after my channel reads the XML file, and then I display on the channel for example the video description, instead of changing &quot; back into a " character for display, it just leaves it as &quot; which obviously doesn't look good to the user.

So my question is what do I need to do to convert these special escaped things back into the right characters for display? Is there an existing function that does this already, or should I just create my own?
0 Kudos
5 REPLIES 5
NB_
Roku Guru

Re: XML Format Issue

it would seem you "over-escaped" things, like say escaping inside <![CDATA[ ]]> or double-escaping.
Give example, let's see what's up.
0 Kudos
johnsonted
Visitor

Re: XML Format Issue

Here is a sample XML file that has an escaped special character:

<feed>
<show>
<contentId>3313</contentId>
<free>Y</free>
<allowAccess>true</allowAccess>
<loggedIn>false</loggedIn>
<description>
In Tom McCook&apos;s latest video, Introducing New Concepts, he shares what is new in his teaching and how he shares this information with his clients. As we continue to understand more about the body, it is important for you to keep learning so you can help your clients the best you can.
</description>
<classType>PI</classType>
<classTypeName>Introduction</classTypeName>
<numChapters>1</numChapters>
<chapter>
<chapterImage>
http://images.pilatesanytime.com/2017/12/08/vthumb_tom_171117_PA5521-70566.jpg
</chapterImage>
<chapterName/>
<chapterDesc/>
<chapterNum>1</chapterNum>
<videoId>6855</videoId>
<position>0</position>
<chpaterMins>1</chpaterMins>
</chapter>
</show>
</feed>


I have a line like this in my Roku code to get the description:

item.description        = validstr(curChapter.description.GetText())


When I output the description to the screen, it does not change "&apos;" into an apostrophe like I hoped it would. Because it's XML I'm forced to encode the apostrophe like that.

Any help appreciated.
0 Kudos
NB_
Roku Guru

Re: XML Format Issue

"johnsonted" wrote:
When I output the description to the screen, it does not change "&apos;" into an apostrophe like I hoped it would.

it does for me:
Brightscript Debugger> xml = createObject("roXmlElement") 
Brightscript Debugger> xml.parse("<description>In Tom McCook&apos;s latest video,</description>")
Brightscript Debugger> ? xml.getText()
In Tom McCook's latest video,

That custom function `validstr()`... it doesn't re-encode ' back to &apos;, i hope?
0 Kudos
johnsonted
Visitor

Re: XML Format Issue

Here's that function and related ones. They are all taken from the Roku example code.

Function validstr(obj As Dynamic) As String
    if isnonemptystr(obj) return obj
    return ""
End Function

Function isstr(obj as dynamic) As Boolean
    if obj = invalid return false
    if GetInterface(obj, "ifString") = invalid return false
    return true
End Function

Function isnonemptystr(obj)
    if isnullorempty(obj) return false
    return true
End Function

Function isnullorempty(obj)
    if obj = invalid return true
    if not isstr(obj) return true
    if Len(obj) = 0 return true
    return false
End Function


The text in this particular example is being displayed on a "roSpringboardScreen" if you think that might make a difference.
0 Kudos
johnsonted
Visitor

Re: XML Format Issue

Aha! I have found the problem. When I looked at the source code (not the output on my web browser) I saw it was indeed a double-encoding problem.

The source code actually had this &amp;apos; but I had been previewing in Chrome which displays it as &apos; and only from viewing source code in chrome did I catch it. So the issue has nothing to do with the Roku code and is a problem with the XML encoding on the server.

Thanks!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.