johnsonted
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2017
02:01 PM
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 " and < turns into < 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 " back into a " character for display, it just leaves it as " 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?
For example, in the XML file where there is a " character this is escaped as " and < turns into < 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 " back into a " character for display, it just leaves it as " 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?
5 REPLIES 5
NB_
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2017
12:26 PM
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.
Give example, let's see what's up.
johnsonted
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018
01:56 PM
Re: XML Format Issue
Here is a sample XML file that has an escaped special character:
I have a line like this in my Roku code to get the description:
When I output the description to the screen, it does not change "'" into an apostrophe like I hoped it would. Because it's XML I'm forced to encode the apostrophe like that.
Any help appreciated.
<feed>
<show>
<contentId>3313</contentId>
<free>Y</free>
<allowAccess>true</allowAccess>
<loggedIn>false</loggedIn>
<description>
In Tom McCook'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 "'" into an apostrophe like I hoped it would. Because it's XML I'm forced to encode the apostrophe like that.
Any help appreciated.
NB_
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018
02:28 PM
Re: XML Format Issue
"johnsonted" wrote:
When I output the description to the screen, it does not change "'" 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'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 ', i hope?
johnsonted
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018
02:38 PM
Re: XML Format Issue
Here's that function and related ones. They are all taken from the Roku example code.
The text in this particular example is being displayed on a "roSpringboardScreen" if you think that might make a difference.
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.
johnsonted
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2018
02:43 PM
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 &apos; but I had been previewing in Chrome which displays it as ' 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!
The source code actually had this &apos; but I had been previewing in Chrome which displays it as ' 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!