1

Hi this is what i do for generating an xml code:

OMFactory factory = OMAbstractFactory.getOMFactory();
OMNamespace nsSequence = factory.createOMNamespace("http://ws.apache.org/ns/synapse", "");
OMElement rootSequence = factory.createOMElement("sequence",nsSequence);


/*<FILTER>*/
OMNamespace nsFilter = factory.createOMNamespace("http://org.apache.synapse/xsd", "ns");        
OMElement filter = factory.createOMElement("filter",nsFilter);
OMAttribute regex = factory.createOMAttribute("regex", null, "applID");
OMAttribute source = factory.createOMAttribute("source", null, "get-property('applicationID')");

filter.addAttribute(regex);
filter.addAttribute(source);

/*<THEN>*/
OMElement then = factory.createOMElement("then",null);          

filter.addChild(then);
rootSequence.addChild(filter);

the generated code is like this one:

<sequence xmlns="http://ws.apache.org/ns/synapse">
    <ns:filter xmlns:ns="http://org.apache.synapse/xsd" regex="APPP" source="get-property('applicationID')">
        <then xmlns=""></then>
    </ns:filter>
</sequence>

The XMLNS="" inside the THEN element is a big problem for me.

i m using axiom-api 1.2.14... and i read somewhere this is a problem (bug) experienced by others (maybe already solver?). Is there a way to work around this problem in order to obtain a clean xml code? or better to solve it?

Alex
  • 1,515
  • 2
  • 22
  • 44
  • a work-around is to add the namespace as attribute: OMAttribute ns = factory.createOMAttribute("xmlns:ns", null, "http://org.apache.synapse/xsd"); filter.addAttribute(ns);... this way should work... but i think it's a bug that should be reported. – Alex Jan 26 '15 at 22:03

1 Answers1

0

You are creating the then element without namespace:

OMElement then = factory.createOMElement("then", null);

Therefore Axiom generates a xmlns="" so that the element has no namespace, exactly as you have requested. In fact, without the xmlns="", the element would have the default namespace http://ws.apache.org/ns/synapse, which would be wrong.

If you think that the namespace declaration is wrong, then this probably means that the element should actually belong to one of the other namespaces used in the document. If that's the case, then you should fix the code to request an element in the right namespace.

Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • Really i need axiom not to override the default namespace declared in the parent node. Writing xmlns="" it does. This behaviour exists in previous axiom api release as written here:https://issues.apache.org/jira/browse/AXIOM-28 dealing with the setDefaultNamespace method.So the point is if axiom allows to create an element without the default namespace specification. As written in the jira link above too a way to work around the issue is to specify namespaces as attribute – Alex Jan 27 '15 at 07:17
  • As I said, this is not a bug. Axiom is strictly doing what your code is requesting it to do. If the result is not what you expect it to be, fix your code. – Andreas Veithen Jan 27 '15 at 07:58
  • could you write a sample code in order to obtain this? ... i'm trying to figure out what should i have to fix. – Alex Jan 27 '15 at 09:07
  • `OMElement then = factory.createOMElement("then", nsSequence);` – Andreas Veithen Jan 27 '15 at 10:01
  • thnx... you were right... i understand now. It works – Alex Jan 28 '15 at 15:37