FML2010
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
12:04 PM
xml question if blank ??
what can i put in case the xml is blank?
for example
<hello></hello>
I tried
if its empty it tosses up errors, so what can be put in its place so that doesnt happen? this above doesnt work either still shows errors as if its empty
thanks!
for example
<hello></hello>
I tried
if e.GetName() = "hello" then
hello = e.GetBody()
end if
next
if hello = "" then
hello = "hello"
end if
if its empty it tosses up errors, so what can be put in its place so that doesnt happen? this above doesnt work either still shows errors as if its empty
thanks!
6 REPLIES 6
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
12:53 PM
Re: xml question if blank ??
Try, if hello = invalid, or if e = invalid.
-JT
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
01:14 PM
Re: xml question if blank ??
For debugging, I find a sprinkling of "print variable" "print type(variable)" (where "variable" is the actual variable) are useful. Just check for the output on the debugging console, and optionally prefix the prints with some identifying text if it's not obvious what's printing when.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!
FML2010
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
01:16 PM
Re: xml question if blank ??
thanks Jim I will try that.
will that allow me to add what ever i want it to equal to?
wont be able to test it till later tonight
will that allow me to add what ever i want it to equal to?
wont be able to test it till later tonight
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
01:53 PM
Re: xml question if blank ??
He's referring to the value testing portion of your example code, where you are testing with
he is implying that e.GetBody() may be returning the invalid object, and not a string at all. In which case you would wan to test for that. From a language standpoint, invalid is not equivalent to the empy string (""), so you need to test for it explicitly if it is possible it might be returned instead.
P.S.
It's generally possible to intuit what type of errors you might get from a sample piece of code if given enough information, but if you are getting error, include what they are. Anything that reduces the amount of work required for someone to help will increase the chance of getting a prompt, correct answer, and not a request for more information or an incorrect assumption about what the problem is. A bit of sample code with lots of print statements printing the state of a current variable (in this case the hello and e variables) before and after any point that might cause the problem, and including the debug output, will make helping much easier. For example, I would have rewritten (and run) the sample code you included as the following (assuming everything but "next" was code):
to which the console output might be (assuming it actually is getting invalid, I don't know)
At which point the problem would be somewhat obvious, if this is the actual output.
Of course, you don't have to be quite that pedantic when posting here, but in adding statements like that (which you would want to remove after identifying and fixing the problem, console prints have a specific performance penalty in my experience) you help illuminate why the code isn't functioning as you expect, in many cases allowing you to figure out and fix the problem without even having to ask how.
The print statement is your friend.
if hello = ""
he is implying that e.GetBody() may be returning the invalid object, and not a string at all. In which case you would wan to test for that. From a language standpoint, invalid is not equivalent to the empy string (""), so you need to test for it explicitly if it is possible it might be returned instead.
P.S.
It's generally possible to intuit what type of errors you might get from a sample piece of code if given enough information, but if you are getting error, include what they are. Anything that reduces the amount of work required for someone to help will increase the chance of getting a prompt, correct answer, and not a request for more information or an incorrect assumption about what the problem is. A bit of sample code with lots of print statements printing the state of a current variable (in this case the hello and e variables) before and after any point that might cause the problem, and including the debug output, will make helping much easier. For example, I would have rewritten (and run) the sample code you included as the following (assuming everything but "next" was code):
print "e is ";type(e)
print "e.GetName() is ";e.GetName()
if e.GetName() = "hello" then
hello = e.GetBody()
end if
print "hello is ";hello
if hello = "" then
hello = "hello"
end if
print "hello is now ";hello
to which the console output might be (assuming it actually is getting invalid, I don't know)
e is roXMLElement
e.GetName() is hello
hello is invalid
hello is now invalid
At which point the problem would be somewhat obvious, if this is the actual output.
Of course, you don't have to be quite that pedantic when posting here, but in adding statements like that (which you would want to remove after identifying and fixing the problem, console prints have a specific performance penalty in my experience) you help illuminate why the code isn't functioning as you expect, in many cases allowing you to figure out and fix the problem without even having to ask how.
The print statement is your friend.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!
FML2010
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2010
02:17 PM
Re: xml question if blank ??
I know it may be empty at times, so if does come back empty i dont want it to throw errors i want it to add something. it can be just " "
or a phrase saying its empty like i posted originally
or a phrase saying its empty like i posted originally
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2010
12:52 AM
Re: xml question if blank ??
If it is empty at times, you can test for it with either of these:
Note that both statements will throw an error if hello is in fact invalid.
-JT
if hello = ""
if hello.Len() = 0
Note that both statements will throw an error if hello is in fact invalid.
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.