Question

I have a strange behavior when parsing a large xml (but I'm not sure if the fact that is large is causing the problem). This is the xml format:

<?xml version="1.0" encoding="UTF-8"?>
  <webservice>
    <control>
   <operation>get_clips</operation>
   <status>0</status>
    </control>
    <data>
       <cat size="4" lang="EN"/>
       <cat size="3" lang="EN"/>
       ' and 19 more other similar 'cat' elements
     </data>
  </webservice> 

and this is the code, where m.rawResponse is the above xml string.

if m.rawResponse <> "" then
  xml = CreateObject("roXMLElement")
  print "################ "; m.rawResponse ' contains the entire xml
  xml.Parse( m.rawResponse )
  print "################ "; m.rawResponse ' contains the entire xml

  ' I've tried like this
  categories = xml.data.GetChildElements()
  print "number of categories: " ; categories.Count() ' prints 14

  ' and also like this
  i = 0
  for each categ in xml.data.cat
     i = i +1    
  end for
  print i ' prints 14
end if 

The problem is that is only processing 14 cat elements, instead of 21 and I really don't know why. Please help me with any ideas. Thanks a lot!

Later edit I've added a check to see if the parsing is successful and something went wrong there. The problem is related to the symbol & - I have in the xml the following line:

<director>Donald Nij & Rick Senjin</director>

How can I resolve this issue, but not on the server side, but on the Roku code? I could not find any solution searching over the internet. Tks.

Was it helpful?

Solution

In the Roku SDK pull the ReplaceSubstring function from the generalUtils.brs and insert it in your project. Use that to replace the "&" in your code with "&amp". You can also use the roRegex component which might be faster. Ideally, you should fix this on the server, because the problem is you are feeding bad xml to your device, anything else is a kludge.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top