Trying to add element results in "prefix is not bound" SAXParseException.

156 views
Skip to first unread message

Jens Helweg

unread,
Dec 17, 2012, 10:52:53 AM12/17/12
to maven-config-p...@googlegroups.com
Hi, 

I am trying to use the config-processor-plugin to add an element (<security:authenticatorClass>) in an xml file which results in 

"The prefix "security" for element "security:authenticatorClass" is not bound."

Looking at the source in com.google.code.configprocessor.processing.xml.XmlAddActionProcessingAdvisor.addNode(Document document, Node node)

shows that the fragment that I try to add is parsed beforehand: 

Document fragment = XmlHelper.parse(textFragment, prefixAndSuffixTextFragment, getParserFeatures()); 

And this results in the error above. 

Is there a way to introduce the namespace declaration for the "security" prefix in any way?
(Or maybe bypass the parsing altogether?)

If I leave out the security prefix everything works well. 
The namespace for the security prefix is defined like this: 
xmlns:security="urn:java:org.jboss.seam.security">

Leandro de Oliveira

unread,
Dec 17, 2012, 10:58:10 AM12/17/12
to maven-config-p...@googlegroups.com
Hi,

Did you take a look at [1] ?
It should work fine if you added the following to your plugin configuration:

<namespaceContexts>
<security>urn:java:org.jboss.seam.security</security>
</namespaceContexts>

[1] http://code.google.com/p/maven-config-processor-plugin/wiki/TransformationConfiguration#XML_Namespaces

2012/12/17 Jens Helweg <blitz...@googlemail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "maven-config-processor-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-config-processor-users/-/529HlVPsHvAJ.
> To post to this group, send email to
> maven-config-p...@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-config-process...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/maven-config-processor-users?hl=en.

Jens Helweg

unread,
Dec 18, 2012, 7:30:06 AM12/18/12
to maven-config-p...@googlegroups.com
Hi, 

Yes, I found the namespace declaration and the link you provided but it does not make a difference. 

Are you sure that the namespace declaration is really used in this specific case?

I let my debugger stop on the SAXParserException. Looking at the stacktrace in the debugger I see the call of
  1. XmlAddActionProcessingAdvisor.addNode(Document, Node)
  2. Which calls XmlHelper.parse(textFragment, prefixAndSuffixTextFragment, getParserFeatures());
  3. In there is a call to newDocumentBuilder()...
  4. And this creates and returns a new DocumentBuilder (and sets the domFactory namespace aware). 
There are parser features which are set on the domFactory but are the namespace included there?

I just looked at the code quickly and certainly I did not understand everything so there's a good chance that my limited view on this is the problem. 
But maybe you can follow my 4 steps and tell me where I am wrong? (or what else I could try to solve my problem?)

Thanks for your help and for the plugin you provided!
> maven-config-processor-users+unsub...@googlegroups.com.

Jens Helweg

unread,
Dec 19, 2012, 5:36:28 AM12/19/12
to maven-config-p...@googlegroups.com
AddOn: 

I let this run through the debugger again and changed the namespace awareness to false at this location: 


in the method: newDocumentBuilder(List<ParserFeature> features)

Then the parser is not complaining anymore. 

Since at this point there is only an xml fragment that is parsed (the element to add) can't you just remove the namespace awareness?

Thanks & regards, 
Jens

Leandro de Oliveira

unread,
Dec 19, 2012, 8:07:39 AM12/19/12
to maven-config-p...@googlegroups.com
Namespaces are useful to guarantee valid xml is being used sometimes.
If we use namespaces configured in the pom.xml file at the spot you
described, will it work for you?

2012/12/19 Jens Helweg <blitz...@googlemail.com>:
>>> > maven-config-process...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/maven-config-processor-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "maven-config-processor-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-config-processor-users/-/QMeNZmtJMqEJ.
>
> To post to this group, send email to
> maven-config-p...@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-config-process...@googlegroups.com.

Jens Helweg

unread,
Dec 19, 2012, 9:42:05 AM12/19/12
to maven-config-p...@googlegroups.com
I am not sure if I understand you correctly: 
You mean you would add a configuration for your plugin which I can set in my pom.xml and which would then turn of/on namespace awareness for the specific spot?
If this is what you mean, then yes, I think this should work because I more or less did this already by changing the namespace awareness for this specific case. 

>>> > For more options, visit this group at
>>> > http://groups.google.com/group/maven-config-processor-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "maven-config-processor-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-config-processor-users/-/QMeNZmtJMqEJ.
>
> To post to this group, send email to
> maven-config-p...@googlegroups.com.
> To unsubscribe from this group, send email to

Jens Helweg

unread,
Dec 19, 2012, 10:57:40 AM12/19/12
to maven-config-p...@googlegroups.com
Meanwhile I checked out the code for the plugin and tried it myself resp. had a closer look at the code. 
I guess my first approach of removing the namespace awareness altogether at com.google.code.configprocessor.processing.xml.XmlHelper.newDocumentBuilder(List<ParserFeature>)
was a bit blunt. 

However, currently I think this should be solved in either one of these two ways: 
1. Make this (somehow) configurable so for the case of adding an element to an xml file the namespace awareness should be switchable, i.e. in this case should be turned off. 
2. Try to add the namespace declarations to the fragment that is getting parsed from the actual xml file the fragment should go to. 

Regards, 
Jens 

Leandro de Oliveira

unread,
Dec 19, 2012, 7:15:08 PM12/19/12
to maven-config-p...@googlegroups.com
We need namespaces to support some xml constructs and xpath so turning
them off should be a last resort.

I've done this kind of transformation before and at the time I put
something like this in my transformation rule:

<add>
<after>//s:modifies</after>
<value>
<![CDATA[
<security:authenticatorClass
xmlns:security="urn:java:org.jboss.seam.security">org.drools.guvnor.server.security.DemoAuthenticator</security:authenticatorClass>
]]>
</value>
</add>

The security namespace is declared in the xml fragment itself.

I'm looking for a way to make the parsing process use namespaces
configured in the pom.xml file so we don't have to "duplicate" these
declarations (if we use them in xpath expressions too) and make the
whole process more intuitive.

Sorry about that :(

2012/12/19 Jens Helweg <blitz...@googlemail.com>:
>>> >>> > maven-config-process...@googlegroups.com.
>>> >>> > For more options, visit this group at
>>> >>> > http://groups.google.com/group/maven-config-processor-users?hl=en.
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "maven-config-processor-users" group.
>>> > To view this discussion on the web visit
>>> >
>>> > https://groups.google.com/d/msg/maven-config-processor-users/-/QMeNZmtJMqEJ.
>>> >
>>> > To post to this group, send email to
>>> > maven-config-p...@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > maven-config-process...@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/maven-config-processor-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "maven-config-processor-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-config-processor-users/-/EgqyhXZb17oJ.
>
> To post to this group, send email to
> maven-config-p...@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-config-process...@googlegroups.com.

Leandro de Oliveira

unread,
Dec 19, 2012, 8:02:37 PM12/19/12
to maven-config-p...@googlegroups.com
I've committed the required changes to use namespaces configured in
the pom.xml in xml fragments, now you should be able to use:

<namespaceContexts>
<security>urn:java:org.jboss.seam.security</security>
</namespaceContexts>

And then let the xml fragment like this:

<security:authenticatorClass>org.drools.guvnor.server.security.DemoAuthenticator</security:authenticatorClass>

Could you please give it a try and let me know if it works?

2012/12/19 Leandro de Oliveira <lehp...@gmail.com>:
Message has been deleted

Jens Helweg

unread,
Dec 20, 2012, 3:19:09 AM12/20/12
to maven-config-p...@googlegroups.com


Great! Thanks a lot. Works as desired.

Leandro de Oliveira

unread,
Dec 20, 2012, 6:42:46 AM12/20/12
to maven-config-p...@googlegroups.com
Good, I'll release version 2.4 after I close issues #40 and #41. I'm
planning to release it in a couple of days.

2012/12/20 Jens Helweg <blitz...@googlemail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "maven-config-processor-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-config-processor-users/-/ScsbOoyoMZwJ.

Leandro de Oliveira

unread,
Dec 21, 2012, 7:15:06 AM12/21/12
to maven-config-p...@googlegroups.com
Version 2.4 has been released and is available at the maven central repo.

Thank you

2012/12/20 Leandro de Oliveira <lehp...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages