You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reported by christopher.klewes, Apr 20, 2011
First I would like to say thanks for your framework. It's really nice and I'm loving to create XML documents with it.
I recently wanted to read from a XML file which has many optional elements and therefore can occure very differing. I stumbled upon #gotoChild(String xPath) which enables the traversal to a specific child. This is really great but unfortunately it throws an Exception if this child doesn't exists. So I found the #hasTag(String xPath) method which can check this. This works great but bloats up my code extremely.
For example I have the following XML document with the root "user" and the element "name" but it also could optionally contain "login" and "password".
<user>
<name>moo</name>
</foo>
To check this the code would look like
if(user.hasTag("name"))
{
String name = user.gotoChild("name").getText()
}
I would like to have something like Groovys XML slurper. It provides unavaiable nodes/tags if you try to traverse to structured which aren't available.
The code could look like this:
String name = user.gotoChild("name").getText()
Instead of throwing a exception here you could collect the state and return an unavailable tag which returns null on the .getText() call. Also if we try to do something like this:
XMLTag address = user.gotoChild("address")
String street = address.gotoChild("street").getText()
Could also work if you provide a unavailable tag which results null in case of unfound structures.
What do you think?
Hope to hear from you!
Best Regards
Chris
Jun 14, 2011 Delete comment Project Member #1 mathieu.carbou
Yes, I also think that having a null object is a very good idea !!
The text was updated successfully, but these errors were encountered:
Reported by christopher.klewes, Apr 20, 2011
First I would like to say thanks for your framework. It's really nice and I'm loving to create XML documents with it.
I recently wanted to read from a XML file which has many optional elements and therefore can occure very differing. I stumbled upon #gotoChild(String xPath) which enables the traversal to a specific child. This is really great but unfortunately it throws an Exception if this child doesn't exists. So I found the #hasTag(String xPath) method which can check this. This works great but bloats up my code extremely.
For example I have the following XML document with the root "user" and the element "name" but it also could optionally contain "login" and "password".
To check this the code would look like
[...]
... and so on!
I would like to have something like Groovys XML slurper. It provides unavaiable nodes/tags if you try to traverse to structured which aren't available.
The code could look like this:
Instead of throwing a exception here you could collect the state and return an unavailable tag which returns null on the .getText() call. Also if we try to do something like this:
Could also work if you provide a unavailable tag which results null in case of unfound structures.
What do you think?
Hope to hear from you!
Best Regards
Chris
Jun 14, 2011 Delete comment Project Member #1 mathieu.carbou
Yes, I also think that having a null object is a very good idea !!
The text was updated successfully, but these errors were encountered: