groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Wagenleitner <john.wagenleit...@gmail.com>
Subject Re: Can anyone comment on this stackoverflow posting that indicates XmlSlurper is actually namespace aware by default
Date Tue, 05 Apr 2016 21:00:17 GMT
Setting namespaceAware to true (default) means that it provides support for
namespaces, so in your sampleDoc it recognizes that an element such as
"xact:update" is actually "{com.here.repl}update" instead of just
"xact:update".  Usually this would be used together with declareNamespace
since the important information is the URI and you wouldn't want to have to
rely on the prefix always being the same.

For example:

    def xml  = new
XmlSlurper(false,true).parseText(sampleDoc).declareNamespace(a:
'com.here.repl', b: 'com.here.repl.data');
    assert xml.'a:update'.'b:table'.'b:after','b:CLASSIFICATION'.text() ==
'UNCLASSIFIED'
    assert xml.'update'.'table'.'after','CLASSIFICATION'.text() ==
'UNCLASSIFIED'

Since it's namespaceAware you can even forgo including the namespace as
long as it's not required to uniquely identify the element.

Setting namespaceAware to false means the parser wont recognize namespaces
so it expects you to access the element by the full name "xact:update".  On
a non-namespaceAware parser using the declareNamespace wont have any affect.




On Tue, Apr 5, 2016 at 1:15 PM, Winnebeck, Jason <
Jason.Winnebeck@windstream.com> wrote:

> After seeing this a few times now, including being bit by it myself and my
> work team, I have submitted a JIRA and PR to remove the 4 confusing
> characters from the Javadoc :).
>
> https://issues.apache.org/jira/browse/GROOVY-7810  XmlSluper default
> constructor documentation about namespace aware incorrect.
> https://github.com/apache/groovy/pull/305  GROOVY-7810 fix XmlSlurper
> default ctor doc
>
> I posted answer to SO explaining the situation
> http://stackoverflow.com/a/36435993/3875382
>
> Jason
>
> -----Original Message-----
> From: garneke [mailto:kenton.garner@issinc.com]
> Sent: Tuesday, April 05, 2016 3:59 PM
> To: users@groovy.incubator.apache.org
> Subject: Re: Can anyone comment on this stackoverflow posting that
> indicates XmlSlurper is actually namespace aware by default
>
> Here is an unsophisticated example…
>
> testparse.groovy
> <http://groovy.329449.n5.nabble.com/file/n5732207/testparse.groovy>
>
>
>
> --
> View this message in context:
> http://groovy.329449.n5.nabble.com/Can-anyone-comment-on-this-stackoverflow-posting-that-indicates-XmlSlurper-is-actually-namespace-awat-tp5732204p5732207.html
> Sent from the Groovy Users mailing list archive at Nabble.com.
>
> ----------------------------------------------------------------------
> This email message and any attachments are for the sole use of the
> intended recipient(s). Any unauthorized review, use, disclosure or
> distribution is prohibited. If you are not the intended recipient, please
> contact the sender by reply email and destroy all copies of the original
> message and any attachments.
>

Mime
View raw message