I’m having trouble handling an XML field that may or may not contanin nil values. How can I check to see if a field contains an nil value and write one if it doesnt? I’m usung the account number in naming a file that iguana creates so I put in an underscore where it doesn’t have one. This if statement works if I have a value, but if I don’t have an account number, then I get an error “Index 1 is out of bounds”
if patientXML.PatientAccountNumber then patientAccount = patientXML.PatientAccountNumber:S()..'_' else patientAccount = '_' end end
Thanks in adavance for any insight you can offer.
If you change it to this, you’ll probably have more luck:
if #patientXML.PatientAccountNumber > 0 and patientXML.PatientAccountNumber then patientAccount = patientXML.PatientAccountNumber:S()..'_' else patientAccount = '_' end end
That will ensure that patientXML.PatientAccountNumber has a child before drilling into it.
I have a feeling that this is exactly what you need:
Then you can write the code much more elegantly in one line:
patientAccount = patientXML.PatientAccountNumber:text()..’_’
Where the text() function is a general reusable ‘node extension’ function.
The source to the text() function is in the above wiki page. You put that into a general re-usable module that you use anytime you are dealing with XML.
It make the code more readable and easier to understand what it’s doing. Hope that helps!
You must be logged in to reply to this topic.
Please don't hesitate to take anonymous feedback survey or leave us a comment.