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

Help with Parsing XML

Hello,

I am new to the forum and am not sure whether the issue I have is related to my XML or to the brightscript XML parsing routine, so I was hoping someone might point me in the right direction.

The code I am using is:


conn = CreateObject("roAssociativeArray")
conn.UrlCategoryFeed = sXMLREsp ' see XML text in post below

xml=CreateObject("roXmlElement")

if not xml.Parse(conn.UrlCategoryFeed) then
print "Can't parse feed - error loan_category_feed 128"
return invalid
endif

The result of running this code is that it always prints the error message in the brightscript debugger.

conn.UrlCategoryFeed is an associative array element, which I believe is also a string (am I misunderstanding this?). The XML in the element/string that I am attempting to parse is (validated by "print conn.UrlCategoryFeed" returning this same string):

<?xml version="1.0" encoding="utf-16"?><TestResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Success>true</Success><ErrorText>OK</ErrorText><BaseDirectory>G:\Video</BaseDirectory><Directories /><Files><FoundItem><IsDirectory>false</IsDirectory><Name>Air Mater (Pixar Short).jpeg</Name><Size>11230</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Air Mater (Pixar Short).mp4</Name><Size>90090791</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Boundin' (Pixar Short).jpeg</Name><Size>9293</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Boundin' (Pixar Short).mp4</Name><Size>84214597</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Burn-E (Pixar Short).jpeg</Name><Size>6394</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Burn-E (Pixar Short).mp4</Name><Size>86745997</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Day &amp; Night (Pixar Short).jpeg</Name><Size>7344</Size><Duration>0</Duration><Items>0</Items></FoundItem><FoundItem><IsDirectory>false</IsDirectory><Name>Day &amp; Night (Pixar Short).mp4</Name><Size>72547816</Size><Duration>0</Duration><Items>0</Items></FoundItem></Files></TestResult>

Can anyone please help me understand why the XML parse is failing? I tried to validate the XML through various web tools, and they all indicate that it is valid. Would the special characters in the XML (e.g., & = &amp; and ') be causing any issues. Any insight would be greatly appreciated!

Thank you!
0 Kudos
2 REPLIES 2
destruk
Streaming Star

Re: Help with Parsing XML

XML is easier to read if it's formatted as XML rather than just copying what displays on the screen. As to why it fails, try removing the schema links? Or try UTF-8 instead of UTF-16? Maybe someone else has better ideas.
Your &amp; is correct already, and the standard ' apostrophe shouldn't cause issues for basic parsing.


<?xml version="1.0" encoding="utf-16"?>
<TestResult xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Success>true</Success>
<ErrorText>OK</ErrorText>
<BaseDirectory>G:\Video</BaseDirectory>
<Directories />
<Files>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Air Mater (Pixar Short).jpeg</Name>
<Size>11230</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Air Mater (Pixar Short).mp4</Name>
<Size>90090791</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Boundin' (Pixar Short).jpeg</Name>
<Size>9293</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Boundin' (Pixar Short).mp4</Name>
<Size>84214597</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Burn-E (Pixar Short).jpeg</Name>
<Size>6394</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Burn-E (Pixar Short).mp4</Name>
<Size>86745997</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Day &amp; Night (Pixar Short).jpeg</Name>
<Size>7344</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
<FoundItem>
<IsDirectory>false</IsDirectory>
<Name>Day &amp; Night (Pixar Short).mp4</Name>
<Size>72547816</Size>
<Duration>0</Duration>
<Items>0</Items>
</FoundItem>
</Files>
</TestResult>
0 Kudos
STARoDev
Visitor

Re: Help with Parsing XML

Using utf-8 fixed it! Thank you!
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.