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: 
greubel
Visitor

XML.Parse() and escaped characters

When parsing an XML data block from a user, the parse() function failed when it came across this sequence.
<tag>Some Title &#5;</tag>

I think that the "&x5;" is an invalid escape sequence (should have two digits) BUT should the parse() fail ?

I reran the block of data and changed the &x5; to &x50; and the block was able to be decoded.
0 Kudos
9 REPLIES 9
RokuMarkn
Visitor

Re: XML.Parse() and escaped characters

If the XML is invalid, why shouldn't the parse fail?
You can check the XML against a validator like http://www.w3schools.com/xml/xml_validator.asp. I believe single digit hex escapes will be rejected.

--Mark
0 Kudos
greubel
Visitor

Re: XML.Parse() and escaped characters

In this case is not the XML, it's the content.
0 Kudos
RokuMarkn
Visitor

Re: XML.Parse() and escaped characters

I don't understand what you mean by "content" here. Do you mean the character is in character data rather than in a tag? It's still part of the XML document and must be properly encoded. If you have an XML document that validates cleanly in a validator but causes parse() to fail, please post it.

--Mark
0 Kudos
greubel
Visitor

Re: XML.Parse() and escaped characters

Validator says No errors ! It fails on "&lt;dc:title&gt;SONY&amp;#5;1&lt;/dc:title&gt;"

<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><Result>&lt;DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" xmlns:arib="urn:schemas-arib-or-jp:elements-1-0/" xmlns:dtcp="urn:schemas-dtcp-com:metadata-1-0/" xmlns:pv="http://www.pv.com/pvns/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"&gt;&lt;item id=&quot;0$3$28I80394&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SILVER_SURFER_VOL_025&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I80650&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SILVER_SURFER_VOL_031&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I80906&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SILVER_SURFER_VOL_032&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I81162&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SILVER_SURFER_VOL_033&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I81418&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SILVER_SURFER_VOL_034&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I122634&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SOLDIER_16X9LB_SIDE_B_NA1&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I36618&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Sons.of.Anarchy.S04E01.Out.HDTV.XviD-ASAP&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I112138&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SONY&amp;#5;1&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I81930&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SPARTAN [2004][ENG][AC3][DVDRIP-M333]-FLAWL3SS&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I68362&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;SPYLOVE1&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I411402&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x01 - The Cage&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I411658&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x02 - Where No Man Has Gone Before&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I411914&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x03 - The Corbomite Maneuver&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I412170&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x04 - Mudd&amp;apos;s Women&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I412426&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x05 - The Enemy Within&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I412682&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x06 - The Man Trap&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I412938&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x07 - The Naked Time&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I413194&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x08 - Charlie X&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I413450&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x09 - Balance of Terror&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I413706&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x10 - What are Little Girls Made of&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I397322&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x11 - Dagger of the Mind&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I413962&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x12 - Miri&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I414218&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x13 - The Conscience of the King&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I414474&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x14 - The Galileo Seven&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;item id=&quot;0$3$28I414730&quot; parentID=&quot;0$3$28&quot; restricted=&quot;1&quot;&gt;&lt;dc:title&gt;Star Trek - 1x15 - Court Martial&lt;/dc:title&gt;&lt;upnp:class&gt;object.item.videoItem.movie&lt;/upnp:class&gt;&lt;/item&gt;&lt;/DIDL-Lite&gt;</Result><NumberReturned>25</NumberReturned><TotalMatches>632</TotalMatches><UpdateID>3</UpdateID></u:BrowseResponse></s:Body></s:Envelope>

0 Kudos
RokuMarkn
Visitor

Re: XML.Parse() and escaped characters

Hold on, you've posted a valid XML string that has invalid XML embedded in it. So are you saying that the string you posted fails when you parse it, or is it the embedded XML (the one with the &#5) that fails? The main XML should parse correctly, in both Brightscript and in the validator. The embedded XML should fail both.

--Mark
0 Kudos
greubel
Visitor

Re: XML.Parse() and escaped characters

Sorry, let me get the value of the returned results.
0 Kudos
greubel
Visitor

Re: XML.Parse() and escaped characters

Ok, he fails on the embedded XML with "XML Parsing Error: reference to invalid character number" !
0 Kudos
EnTerr
Roku Guru

Re: XML.Parse() and escaped characters

"greubel" wrote:
<tag>Some Title &#5;</tag>
I think that the "&x5;" is an invalid escape sequence (should have two digits) BUT should the parse() fail ?

What, why two digits - i dont get it. The following passes just fine through the validator (http://validator.w3.org/check😞
<?xml version="1.0" ?> 
<tag>Some Title &#9;</tag>

does it xml.parse()?
0 Kudos
TheEndless
Channel Surfer

Re: XML.Parse() and escaped characters

"EnTerr" wrote:
"greubel" wrote:
<tag>Some Title &#5;</tag>
I think that the "&x5;" is an invalid escape sequence (should have two digits) BUT should the parse() fail ?

What, why two digits - i dont get it. The following passes just fine through the validator (http://validator.w3.org/check😞
<?xml version="1.0" ?> 
<tag>Some Title &#9;</tag>

does it xml.parse()?

I suspect 9 is a special case, because it's a whitespace character that can be represented in ASCII/UTF-7/UTF-8/etc (it's a tab). 5 cannot. The fact that it's only a single digit is inconsequential. Adding a zero just converts it to a completely different character (capital P).
xml.Parse() and the validator can both parse &#9;. Neither can parse &#5;.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
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.