You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Xinjun Chen <xj...@gmail.com> on 2007/01/10 03:36:15 UTC

[Axis2] Namespace issue during conversion from DOM Element to OMElement

Hi,

I am trying to convert a DOM Element to OMElement using the following toOM
code in  org.apache.axis2.security.util.Axis2Util.

 public static OMElement toOM(Element element) throws Exception {
  try {
*   org.apache.xml.security.Init.init();
*   ByteArrayOutputStream os = new ByteArrayOutputStream();
   XMLUtils.outputDOM(element, os, true);

   ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
   XMLStreamReader reader = XMLInputFactory.newInstance
().createXMLStreamReader(is);

   StAXOMBuilder builder = new StAXOMBuilder(reader);
   builder.setCache(true);
   return builder.getDocumentElement();
  } catch (XMLStreamException e) {
   log.fatal(e.getMessage(), e);
   throw new Exception("Error when converting from DOM Element to OM.");
  }

There are two problems with the code:
1. I must add the bolded line in the toOM() method.
2. This method seems not deal with namespace correctly.

My original DOM Element is as follows:
<?xml version="1.0" encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn*xmlns="
**http://cis.com"*
><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn<http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
>

But when I use the method to convert the DOM Element into OMElement, it
reads:
<getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>

It seems that the namespace is ignored by the Axis2Util.toOM().

After I add the OMElement to a SOAPEnvelope using the following code, every
element is qualified with "" namespace which is unexpected.

SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
OMElement om = Axis2Util.toOM((Element)retNode);
envelope.getBody().addChild(om);

/*******************************
Result SOAPEnvelope
*******************************/
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope
 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
 <soapenv:Header />
 <soapenv:Body>
  <getHearingDetailsByCaseNoWSReturn xmlns="">
   <hearingDetailsVO xmlns="">
    <duration xmlns="" />
    <applicationNo xmlns="">sAppNo0</applicationNo>
   </hearingDetailsVO>
  </getHearingDetailsByCaseNoWSReturn>
 </soapenv:Body>
</soapenv:Envelope>


Could anyone tell me how can I solve the problems?


Regards,
Xinjun

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Ruchith,

setNamespaceAware to the original DocumentBuilderFactory solve the problem
partially.

Now the DOM Element reads:
<?xml version="1.0"
  encoding="UTF-8"?>
<getHearingDetailsByCaseNoWSReturn *xmlns="http://cis.com"*>
    <hearingDetailsVO *xmlns="http://vo.cis.com"*>
      <duration/>
      <applicationNo>sAppNo0</applicationNo>
    </hearingDetailsVO>
</getHearingDetailsByCaseNoWSReturn>

But the OMElement reads:
 <getHearingDetailsByCaseNoWSReturn *xmlns=""*>
    <hearingDetailsVO *xmlns="http://vo.cis.com"*>
      <duration/>
      <applicationNo>sAppNo0</applicationNo>
    </hearingDetailsVO>
</getHearingDetailsByCaseNoWSReturn>

Observations:
1. After I setNamespaceAware to the original DOM DocumentBuilderFactory, the
inner element <hearingDetailsVO> gets correct namespace. But root
element <getHearingDetailsByCaseNoWSReturn> does not. The namespace of
<getHearingDetailsByCaseNoWSReturn> is lost. I created this element in the
following way:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
Element root = doc.createElementNS("http://cis.com",
"getHearingDetailsByCaseNoWSReturn");

I think OMElement does not include "http://cis.com" as namespace because "
http://cis.com" is not explicitly declared as a namespace in DOM doc. I
searched the interfaces of Document and Element, but cannot find a way to
explicitly declare a namespace.
I think I need to treat namespace as attribute in DOM. Please correct me if
I am wrong.

Thus I added one line to declare xmlns as attribute.

root.setAttribute("xmlns", "http://cis.com").

Is there any other elegant way?


2. Do you have a good way to remove all null elements like <duration/>? The
original DOM Element also contains other null elements which contains no
value.



Regards,
Xinjun




On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
>
> Hi Xinjun,
>
> How did u create the DOM element that is to be converted to OM? If you
> read it from a file you MUST make sure you the DocumentBuilderFactory
> instance that you use to create the DocumentBuilder instance that
> parses the xml is *namspaceAware*.
>
> Please see here[1] for an example.
>
> Thanks,
> Ruchith
>
> [1] http://rafb.net/p/DDc2NH37.html
>
>
> On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi,
> >
> > I am trying to convert a DOM Element to OMElement using the following
> toOM
> > code in  org.apache.axis2.security.util.Axis2Util.
> >
> >  public static OMElement toOM(Element element) throws Exception {
> >   try {
> >    org.apache.xml.security.Init.init();
> >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> >    XMLUtils.outputDOM (element, os, true);
> >
> >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
> >    XMLStreamReader reader =
> > XMLInputFactory.newInstance().createXMLStreamReader(is);
> >
> >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> >    builder.setCache(true);
> >    return builder.getDocumentElement();
> >   } catch (XMLStreamException e) {
> >    log.fatal(e.getMessage(), e);
> >    throw new Exception("Error when converting from DOM Element to OM.");
> >   }
> >
> > There are two problems with the code:
> > 1. I must add the bolded line in the toOM() method.
> > 2. This method seems not deal with namespace correctly.
> >
> > My original DOM Element is as follows:
> > <?xml version="1.0"
> > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > xmlns="
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> >
> > But when I use the method to convert the DOM Element into OMElement, it
> > reads:
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> >
> >
> > It seems that the namespace is ignored by the Axis2Util.toOM().
> >
> > After I add the OMElement to a SOAPEnvelope using the following code,
> every
> > element is qualified with "" namespace which is unexpected.
> >
> > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > OMElement om = Axis2Util.toOM((Element)retNode);
> > envelope.getBody().addChild(om);
> >
> > /*******************************
> > Result SOAPEnvelope
> > *******************************/
> > <?xml version='1.0' encoding='utf-8'?>
> > <soapenv:Envelope
> >  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
> >  <soapenv:Header />
> >  <soapenv:Body>
> >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> >    <hearingDetailsVO xmlns="">
> >     <duration xmlns="" />
> >     <applicationNo xmlns="">sAppNo0</applicationNo>
> >    </hearingDetailsVO>
> >   </getHearingDetailsByCaseNoWSReturn>
> >  </soapenv:Body>
> > </soapenv:Envelope>
> >
> >
> > Could anyone tell me how can I solve the problems?
> >
> >
> > Regards,
> > Xinjun
>
>
> --
> www.ruchith.org
> www.wso2.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Paul,

Thank you for your responsive reply.
Sorry, I forget to mention, I am using the deserialized object to invoke an
EJB deploy in the intranet using RMI. And serialize the returned object to
the external client. The bean classes contains some HashMap and Vector, is
that also OK? From my understanding, if there is no mapping information like
the class type of the key and value of a HashMap, the data binding tool will
not be able to do the databinding. If I use ADB, how can I specify those
mapping information? And during databinding, some data member of certain
classes can be null. And if they are null, there should be no corresponding
XML element. Is there any way to specify this?

Regards,
Xinjun

On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> Xinjun
>
> There is actually some (little-known) code in ADB to directly convert
> objects to OM/Stax simply based on reflection. I have to admit that
> when I've tested this in the past its been a little basic, but it
> might work for you.
>
> The class is org.apache.axis2.databinding.utils.BeanUtil
>
> It can be used to create a pull parser from an Object like this:
> XMLStreamReader pp = BeanUtil.getPullParser(beanObject);
>
> But in fact it seems to me that you should simply look at the POJO
> examples in the Axis2 samples. After all I think that is what you are
> doing.
>
> Paul
>
>
>
>
>
> On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi Paul,
> >
> > Thank you for your reply.
> > Before I chose Castor, I have already looked into JIBX. JIBX also enable
> > binding for Java collections. But what I understand JIBX databinding is
> > that, JIBX needs to modify the bytecode. The original class file will be
> > replaced by the new class file which added some
> marshalling/unmarshalling
> > related codes. I have sent an email to Dennis on whether JIBX can
> separating
> > the marshalling code from the original class, but did not get response.
> I
> > did not find example of using JIBX and keeping the original class
> unchanged.
> > Please enlighten me this if you know how to do this. Any comments or
> > pointers will be helpful.
> >
> > I also want to use StAX-based binding framework directly if possible.
> >
> >
> >
> > On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > Xinjun
> > >
> > > Have you tried some of the databinding frameworks that Axis2 supports?
> > > Maybe JIBX or XMLBeans, or even ADB would suit you better. The DOM
> > > approach will be very slow indeed compared to using a STAX based
> > > binding framework.
> > >
> > > The DOM over OM is in axiom-dom-**.jar. This is an implementation of
> > > DOM that uses Axiom underneath, and so can let you switch between
> > > them.
> > >
> > > Paul
> > >
> > > On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > Hi Paul,
> > > >
> > > > Thank you for your reply.
> > > > I am using Castor to create DOM Node, and then convert the DOM Node
> into
> > OM.
> > > > It seems that Castor does not support AXIOM.
> > > >
> > > > I choose Castor marshalling framework because I got the class files
> from
> > my
> > > > client and I am not supposed to modify the class files. And there
> are
> > some
> > > > java.util.Map and java.util.Vector inside the class file. It hits me
> > that
> > > > Castor marshalling framework may satisfy both requirements. Do I
> have
> > other
> > > > options which may satisfy these two requirements?
> > > >
> > > > Do you mean if I construct the OM directly I will have control on
> > > > eliminating the null elements at node creation time?
> > > > What do you mean there is a version of DOM that uses OM underneath?
> > > >
> > > > Thanks.
> > > >
> > > > Regards,
> > > > Xinjun
> > > >
> > > >
> > > >
> > > > On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > > > Xinjun
> > > > >
> > > > > How are you creating the DOM element? There might be some options
> to
> > > > > use OM directly. Firstly, maybe you could just code to OM. Or if
> you
> > > > > already have lots of DOM code then there is also a version of DOM
> that
> > > > > uses OM underneath.
> > > > >
> > > > > Paul
> > > > >
> > > > > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > > > Hi Ruchith,
> > > > > >
> > > > > > setNamespaceAware to the original DocumentBuilderFactory solve
> the
> > > > problem
> > > > > > partially.
> > > > > >
> > > > > > Now the DOM Element reads:
> > > > > > <?xml version=" 1.0"
> > > > > >   encoding="UTF-8"?>
> > > > > > <getHearingDetailsByCaseNoWSReturn
> > > > xmlns="http://cis.com">
> > > > > >     <hearingDetailsVO xmlns=" http://vo.cis.com">
> > > > > >       <duration/>
> > > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > > >     </hearingDetailsVO>
> > > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > > But the OMElement reads:
> > > > > >
> > > > > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > > > > >       <duration/>
> > > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > > >     </hearingDetailsVO>
> > > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > > Observations:
> > > > > > 1. After I setNamespaceAware to the original DOM
> > DocumentBuilderFactory,
> > > > the
> > > > > > inner element <hearingDetailsVO> gets correct namespace. But
> root
> > > > element
> > > > > > <getHearingDetailsByCaseNoWSReturn> does not. The
> > > > namespace
> > > > > > of <getHearingDetailsByCaseNoWSReturn> is lost. I
> > > > created
> > > > > > this element in the following way:
> > > > > >
> > > > > > DocumentBuilderFactory dbf =
> > > > > > DocumentBuilderFactory.newInstance();
> > > > > > dbf.setNamespaceAware (true);
> > > > > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > > > > Element root = doc.createElementNS(" http://cis.com",
> > > > > > "getHearingDetailsByCaseNoWSReturn");
> > > > > >
> > > > > > I think OMElement does not include "http://cis.com" as namespace
> > because
> > > > > > " http://cis.com" is not explicitly declared as a namespace in
> DOM
> > doc.
> > > > I
> > > > > > searched the interfaces of Document and Element, but cannot find
> a
> > way
> > > > to
> > > > > > explicitly declare a namespace.
> > > > > > I think I need to treat namespace as attribute in DOM. Please
> > correct me
> > > > if
> > > > > > I am wrong.
> > > > > >
> > > > > > Thus I added one line to declare xmlns as attribute.
> > > > > >
> > > > > > root.setAttribute("xmlns", " http://cis.com").
> > > > > >
> > > > > > Is there any other elegant way?
> > > > > >
> > > > > >
> > > > > > 2. Do you have a good way to remove all null elements like
> > <duration/>?
> > > > The
> > > > > > original DOM Element also contains other null elements which
> > contains no
> > > > > > value.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Regards,
> > > > > > Xinjun
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > > > > > Hi Xinjun,
> > > > > > >
> > > > > > > How did u create the DOM element that is to be converted to
> OM? If
> > you
> > > > > > > read it from a file you MUST make sure you the
> > DocumentBuilderFactory
> > > > > > > instance that you use to create the DocumentBuilder instance
> that
> > > > > > > parses the xml is *namspaceAware*.
> > > > > > >
> > > > > > > Please see here[1] for an example.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Ruchith
> > > > > > >
> > > > > > > [1] http://rafb.net/p/DDc2NH37.html
> > > > > > >
> > > > > > >
> > > > > > > On 1/10/07, Xinjun Chen < xjchen001@gmail.com> wrote:
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I am trying to convert a DOM Element to OMElement using the
> > > > following
> > > > > > toOM
> > > > > > > > code in
> > org.apache.axis2.security.util.Axis2Util.
> > > > > > > >
> > > > > > > >  public static OMElement toOM(Element element) throws
> Exception
> > {
> > > > > > > >   try {
> > > > > > > >     org.apache.xml.security.Init.init();
> > > > > > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > > > > > >     XMLUtils.outputDOM (element, os, true);
> > > > > > > >
> > > > > > > >    ByteArrayInputStream is = new ByteArrayInputStream(
> > > > os.toByteArray());
> > > > > > > >    XMLStreamReader reader =
> > > > > > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > > > > > >
> > > > > > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > > > > > >     builder.setCache(true);
> > > > > > > >    return builder.getDocumentElement();
> > > > > > > >   } catch (XMLStreamException e) {
> > > > > > > >    log.fatal(e.getMessage (), e);
> > > > > > > >    throw new Exception("Error when converting from DOM
> Element
> > to
> > > > OM.");
> > > > > > > >   }
> > > > > > > >
> > > > > > > > There are two problems with the code:
> > > > > > > > 1. I must add the bolded line in the toOM() method.
> > > > > > > > 2. This method seems not deal with namespace correctly.
> > > > > > > >
> > > > > > > > My original DOM Element is as follows:
> > > > > > > > <?xml version=" 1.0"
> > > > > > > >
> > > > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > > > > > xmlns="
> > > > > > > >
> > > > > >
> > > >
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > > >
> > > > > > > > But when I use the method to convert the DOM Element into
> > OMElement,
> > > > it
> > > > > > > > reads:
> > > > > > > >
> > > > > >
> > > >
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > > > > > >
> > > > > >
> > > >
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > > >
> > > > > > > >
> > > > > > > > It seems that the namespace is ignored by the Axis2Util.toOM
> ().
> > > > > > > >
> > > > > > > > After I add the OMElement to a SOAPEnvelope using the
> following
> > > > code,
> > > > > > every
> > > > > > > > element is qualified with "" namespace which is unexpected.
> > > > > > > >
> > > > > > > > SOAPFactory fac =
> > > > OMAbstractFactory.getSOAP11Factory();
> > > > > > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > > > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > > > > > envelope.getBody().addChild(om);
> > > > > > > >
> > > > > > > > /*******************************
> > > > > > > > Result SOAPEnvelope
> > > > > > > > *******************************/
> > > > > > > > <?xml version=' 1.0' encoding='utf-8'?>
> > > > > > > > <soapenv:Envelope
> > > > > > > >  xmlns:soapenv="
> > > > > > http://schemas.xmlsoap.org/soap/envelope/ ">
> > > > > > > >  <soapenv:Header />
> > > > > > > >  <soapenv:Body>
> > > > > > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > > > >    <hearingDetailsVO xmlns="">
> > > > > > > >     <duration xmlns="" />
> > > > > > > >     <applicationNo
> > xmlns="">sAppNo0</applicationNo>
> > > > > > > >    </hearingDetailsVO>
> > > > > > > >   </getHearingDetailsByCaseNoWSReturn>
> > > > > > > >  </soapenv:Body>
> > > > > > > > </soapenv:Envelope>
> > > > > > > >
> > > > > > > >
> > > > > > > > Could anyone tell me how can I solve the problems?
> > > > > > > >
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Xinjun
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > www.ruchith.org
> > > > > > > www.wso2.org
> > > > > > >
> > > > > > >
> > > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail:
> > > > > > axis-user-unsubscribe@ws.apache.org
> > > > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Paul Fremantle
> > > > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > > > >
> > > > > http://bloglines.com/blog/paulfremantle
> > > > > paul@wso2.com
> > > > >
> > > > > "Oxygenating the Web Service Platform", www.wso2.com
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > axis-user-unsubscribe@ws.apache.org
> > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Paul Fremantle
> > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > >
> > > http://bloglines.com/blog/paulfremantle
> > > paul@wso2.com
> > >
> > > "Oxygenating the Web Service Platform", www.wso2.com
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> >
>
>
> --
> Paul Fremantle
> VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
>
> http://bloglines.com/blog/paulfremantle
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Paul,

Thank you for your responsive reply.
Sorry, I forget to mention, I am using the deserialized object to invoke an
EJB deploy in the intranet using RMI. And serialize the returned object to
the external client. The bean classes contains some HashMap and Vector, is
that also OK? From my understanding, if there is no mapping information like
the class type of the key and value of a HashMap, the data binding tool will
not be able to do the databinding. If I use ADB, how can I specify those
mapping information? And during databinding, some data member of certain
classes can be null. And if they are null, there should be no corresponding
XML element. Is there any way to specify this?

Regards,
Xinjun

On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> Xinjun
>
> There is actually some (little-known) code in ADB to directly convert
> objects to OM/Stax simply based on reflection. I have to admit that
> when I've tested this in the past its been a little basic, but it
> might work for you.
>
> The class is org.apache.axis2.databinding.utils.BeanUtil
>
> It can be used to create a pull parser from an Object like this:
> XMLStreamReader pp = BeanUtil.getPullParser(beanObject);
>
> But in fact it seems to me that you should simply look at the POJO
> examples in the Axis2 samples. After all I think that is what you are
> doing.
>
> Paul
>
>
>
>
>
> On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi Paul,
> >
> > Thank you for your reply.
> > Before I chose Castor, I have already looked into JIBX. JIBX also enable
> > binding for Java collections. But what I understand JIBX databinding is
> > that, JIBX needs to modify the bytecode. The original class file will be
> > replaced by the new class file which added some
> marshalling/unmarshalling
> > related codes. I have sent an email to Dennis on whether JIBX can
> separating
> > the marshalling code from the original class, but did not get response.
> I
> > did not find example of using JIBX and keeping the original class
> unchanged.
> > Please enlighten me this if you know how to do this. Any comments or
> > pointers will be helpful.
> >
> > I also want to use StAX-based binding framework directly if possible.
> >
> >
> >
> > On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > Xinjun
> > >
> > > Have you tried some of the databinding frameworks that Axis2 supports?
> > > Maybe JIBX or XMLBeans, or even ADB would suit you better. The DOM
> > > approach will be very slow indeed compared to using a STAX based
> > > binding framework.
> > >
> > > The DOM over OM is in axiom-dom-**.jar. This is an implementation of
> > > DOM that uses Axiom underneath, and so can let you switch between
> > > them.
> > >
> > > Paul
> > >
> > > On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > Hi Paul,
> > > >
> > > > Thank you for your reply.
> > > > I am using Castor to create DOM Node, and then convert the DOM Node
> into
> > OM.
> > > > It seems that Castor does not support AXIOM.
> > > >
> > > > I choose Castor marshalling framework because I got the class files
> from
> > my
> > > > client and I am not supposed to modify the class files. And there
> are
> > some
> > > > java.util.Map and java.util.Vector inside the class file. It hits me
> > that
> > > > Castor marshalling framework may satisfy both requirements. Do I
> have
> > other
> > > > options which may satisfy these two requirements?
> > > >
> > > > Do you mean if I construct the OM directly I will have control on
> > > > eliminating the null elements at node creation time?
> > > > What do you mean there is a version of DOM that uses OM underneath?
> > > >
> > > > Thanks.
> > > >
> > > > Regards,
> > > > Xinjun
> > > >
> > > >
> > > >
> > > > On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > > > Xinjun
> > > > >
> > > > > How are you creating the DOM element? There might be some options
> to
> > > > > use OM directly. Firstly, maybe you could just code to OM. Or if
> you
> > > > > already have lots of DOM code then there is also a version of DOM
> that
> > > > > uses OM underneath.
> > > > >
> > > > > Paul
> > > > >
> > > > > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > > > Hi Ruchith,
> > > > > >
> > > > > > setNamespaceAware to the original DocumentBuilderFactory solve
> the
> > > > problem
> > > > > > partially.
> > > > > >
> > > > > > Now the DOM Element reads:
> > > > > > <?xml version=" 1.0"
> > > > > >   encoding="UTF-8"?>
> > > > > > <getHearingDetailsByCaseNoWSReturn
> > > > xmlns="http://cis.com">
> > > > > >     <hearingDetailsVO xmlns=" http://vo.cis.com">
> > > > > >       <duration/>
> > > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > > >     </hearingDetailsVO>
> > > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > > But the OMElement reads:
> > > > > >
> > > > > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > > > > >       <duration/>
> > > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > > >     </hearingDetailsVO>
> > > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > > Observations:
> > > > > > 1. After I setNamespaceAware to the original DOM
> > DocumentBuilderFactory,
> > > > the
> > > > > > inner element <hearingDetailsVO> gets correct namespace. But
> root
> > > > element
> > > > > > <getHearingDetailsByCaseNoWSReturn> does not. The
> > > > namespace
> > > > > > of <getHearingDetailsByCaseNoWSReturn> is lost. I
> > > > created
> > > > > > this element in the following way:
> > > > > >
> > > > > > DocumentBuilderFactory dbf =
> > > > > > DocumentBuilderFactory.newInstance();
> > > > > > dbf.setNamespaceAware (true);
> > > > > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > > > > Element root = doc.createElementNS(" http://cis.com",
> > > > > > "getHearingDetailsByCaseNoWSReturn");
> > > > > >
> > > > > > I think OMElement does not include "http://cis.com" as namespace
> > because
> > > > > > " http://cis.com" is not explicitly declared as a namespace in
> DOM
> > doc.
> > > > I
> > > > > > searched the interfaces of Document and Element, but cannot find
> a
> > way
> > > > to
> > > > > > explicitly declare a namespace.
> > > > > > I think I need to treat namespace as attribute in DOM. Please
> > correct me
> > > > if
> > > > > > I am wrong.
> > > > > >
> > > > > > Thus I added one line to declare xmlns as attribute.
> > > > > >
> > > > > > root.setAttribute("xmlns", " http://cis.com").
> > > > > >
> > > > > > Is there any other elegant way?
> > > > > >
> > > > > >
> > > > > > 2. Do you have a good way to remove all null elements like
> > <duration/>?
> > > > The
> > > > > > original DOM Element also contains other null elements which
> > contains no
> > > > > > value.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Regards,
> > > > > > Xinjun
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > > > > > Hi Xinjun,
> > > > > > >
> > > > > > > How did u create the DOM element that is to be converted to
> OM? If
> > you
> > > > > > > read it from a file you MUST make sure you the
> > DocumentBuilderFactory
> > > > > > > instance that you use to create the DocumentBuilder instance
> that
> > > > > > > parses the xml is *namspaceAware*.
> > > > > > >
> > > > > > > Please see here[1] for an example.
> > > > > > >
> > > > > > > Thanks,
> > > > > > > Ruchith
> > > > > > >
> > > > > > > [1] http://rafb.net/p/DDc2NH37.html
> > > > > > >
> > > > > > >
> > > > > > > On 1/10/07, Xinjun Chen < xjchen001@gmail.com> wrote:
> > > > > > > > Hi,
> > > > > > > >
> > > > > > > > I am trying to convert a DOM Element to OMElement using the
> > > > following
> > > > > > toOM
> > > > > > > > code in
> > org.apache.axis2.security.util.Axis2Util.
> > > > > > > >
> > > > > > > >  public static OMElement toOM(Element element) throws
> Exception
> > {
> > > > > > > >   try {
> > > > > > > >     org.apache.xml.security.Init.init();
> > > > > > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > > > > > >     XMLUtils.outputDOM (element, os, true);
> > > > > > > >
> > > > > > > >    ByteArrayInputStream is = new ByteArrayInputStream(
> > > > os.toByteArray());
> > > > > > > >    XMLStreamReader reader =
> > > > > > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > > > > > >
> > > > > > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > > > > > >     builder.setCache(true);
> > > > > > > >    return builder.getDocumentElement();
> > > > > > > >   } catch (XMLStreamException e) {
> > > > > > > >    log.fatal(e.getMessage (), e);
> > > > > > > >    throw new Exception("Error when converting from DOM
> Element
> > to
> > > > OM.");
> > > > > > > >   }
> > > > > > > >
> > > > > > > > There are two problems with the code:
> > > > > > > > 1. I must add the bolded line in the toOM() method.
> > > > > > > > 2. This method seems not deal with namespace correctly.
> > > > > > > >
> > > > > > > > My original DOM Element is as follows:
> > > > > > > > <?xml version=" 1.0"
> > > > > > > >
> > > > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > > > > > xmlns="
> > > > > > > >
> > > > > >
> > > >
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > > >
> > > > > > > > But when I use the method to convert the DOM Element into
> > OMElement,
> > > > it
> > > > > > > > reads:
> > > > > > > >
> > > > > >
> > > >
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > > > > > >
> > > > > >
> > > >
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > > >
> > > > > > > >
> > > > > > > > It seems that the namespace is ignored by the Axis2Util.toOM
> ().
> > > > > > > >
> > > > > > > > After I add the OMElement to a SOAPEnvelope using the
> following
> > > > code,
> > > > > > every
> > > > > > > > element is qualified with "" namespace which is unexpected.
> > > > > > > >
> > > > > > > > SOAPFactory fac =
> > > > OMAbstractFactory.getSOAP11Factory();
> > > > > > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > > > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > > > > > envelope.getBody().addChild(om);
> > > > > > > >
> > > > > > > > /*******************************
> > > > > > > > Result SOAPEnvelope
> > > > > > > > *******************************/
> > > > > > > > <?xml version=' 1.0' encoding='utf-8'?>
> > > > > > > > <soapenv:Envelope
> > > > > > > >  xmlns:soapenv="
> > > > > > http://schemas.xmlsoap.org/soap/envelope/ ">
> > > > > > > >  <soapenv:Header />
> > > > > > > >  <soapenv:Body>
> > > > > > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > > > >    <hearingDetailsVO xmlns="">
> > > > > > > >     <duration xmlns="" />
> > > > > > > >     <applicationNo
> > xmlns="">sAppNo0</applicationNo>
> > > > > > > >    </hearingDetailsVO>
> > > > > > > >   </getHearingDetailsByCaseNoWSReturn>
> > > > > > > >  </soapenv:Body>
> > > > > > > > </soapenv:Envelope>
> > > > > > > >
> > > > > > > >
> > > > > > > > Could anyone tell me how can I solve the problems?
> > > > > > > >
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Xinjun
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > www.ruchith.org
> > > > > > > www.wso2.org
> > > > > > >
> > > > > > >
> > > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > > > To unsubscribe, e-mail:
> > > > > > axis-user-unsubscribe@ws.apache.org
> > > > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Paul Fremantle
> > > > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > > > >
> > > > > http://bloglines.com/blog/paulfremantle
> > > > > paul@wso2.com
> > > > >
> > > > > "Oxygenating the Web Service Platform", www.wso2.com
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > axis-user-unsubscribe@ws.apache.org
> > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Paul Fremantle
> > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > >
> > > http://bloglines.com/blog/paulfremantle
> > > paul@wso2.com
> > >
> > > "Oxygenating the Web Service Platform", www.wso2.com
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> >
>
>
> --
> Paul Fremantle
> VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
>
> http://bloglines.com/blog/paulfremantle
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Paul Fremantle <pz...@gmail.com>.
Xinjun

There is actually some (little-known) code in ADB to directly convert
objects to OM/Stax simply based on reflection. I have to admit that
when I've tested this in the past its been a little basic, but it
might work for you.

The class is org.apache.axis2.databinding.utils.BeanUtil

It can be used to create a pull parser from an Object like this:
XMLStreamReader pp = BeanUtil.getPullParser(beanObject);

But in fact it seems to me that you should simply look at the POJO
examples in the Axis2 samples. After all I think that is what you are
doing.

Paul





On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> Hi Paul,
>
> Thank you for your reply.
> Before I chose Castor, I have already looked into JIBX. JIBX also enable
> binding for Java collections. But what I understand JIBX databinding is
> that, JIBX needs to modify the bytecode. The original class file will be
> replaced by the new class file which added some marshalling/unmarshalling
> related codes. I have sent an email to Dennis on whether JIBX can separating
> the marshalling code from the original class, but did not get response. I
> did not find example of using JIBX and keeping the original class unchanged.
> Please enlighten me this if you know how to do this. Any comments or
> pointers will be helpful.
>
> I also want to use StAX-based binding framework directly if possible.
>
>
>
> On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
> > Xinjun
> >
> > Have you tried some of the databinding frameworks that Axis2 supports?
> > Maybe JIBX or XMLBeans, or even ADB would suit you better. The DOM
> > approach will be very slow indeed compared to using a STAX based
> > binding framework.
> >
> > The DOM over OM is in axiom-dom-**.jar. This is an implementation of
> > DOM that uses Axiom underneath, and so can let you switch between
> > them.
> >
> > Paul
> >
> > On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > Hi Paul,
> > >
> > > Thank you for your reply.
> > > I am using Castor to create DOM Node, and then convert the DOM Node into
> OM.
> > > It seems that Castor does not support AXIOM.
> > >
> > > I choose Castor marshalling framework because I got the class files from
> my
> > > client and I am not supposed to modify the class files. And there are
> some
> > > java.util.Map and java.util.Vector inside the class file. It hits me
> that
> > > Castor marshalling framework may satisfy both requirements. Do I have
> other
> > > options which may satisfy these two requirements?
> > >
> > > Do you mean if I construct the OM directly I will have control on
> > > eliminating the null elements at node creation time?
> > > What do you mean there is a version of DOM that uses OM underneath?
> > >
> > > Thanks.
> > >
> > > Regards,
> > > Xinjun
> > >
> > >
> > >
> > > On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > > Xinjun
> > > >
> > > > How are you creating the DOM element? There might be some options to
> > > > use OM directly. Firstly, maybe you could just code to OM. Or if you
> > > > already have lots of DOM code then there is also a version of DOM that
> > > > uses OM underneath.
> > > >
> > > > Paul
> > > >
> > > > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > > Hi Ruchith,
> > > > >
> > > > > setNamespaceAware to the original DocumentBuilderFactory solve the
> > > problem
> > > > > partially.
> > > > >
> > > > > Now the DOM Element reads:
> > > > > <?xml version=" 1.0"
> > > > >   encoding="UTF-8"?>
> > > > > <getHearingDetailsByCaseNoWSReturn
> > > xmlns="http://cis.com">
> > > > >     <hearingDetailsVO xmlns=" http://vo.cis.com">
> > > > >       <duration/>
> > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > >     </hearingDetailsVO>
> > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > >
> > > > > But the OMElement reads:
> > > > >
> > > > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > > > >       <duration/>
> > > > >       <applicationNo>sAppNo0</applicationNo>
> > > > >     </hearingDetailsVO>
> > > > > </getHearingDetailsByCaseNoWSReturn>
> > > > >
> > > > > Observations:
> > > > > 1. After I setNamespaceAware to the original DOM
> DocumentBuilderFactory,
> > > the
> > > > > inner element <hearingDetailsVO> gets correct namespace. But root
> > > element
> > > > > <getHearingDetailsByCaseNoWSReturn> does not. The
> > > namespace
> > > > > of <getHearingDetailsByCaseNoWSReturn> is lost. I
> > > created
> > > > > this element in the following way:
> > > > >
> > > > > DocumentBuilderFactory dbf =
> > > > > DocumentBuilderFactory.newInstance();
> > > > > dbf.setNamespaceAware (true);
> > > > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > > > Element root = doc.createElementNS(" http://cis.com",
> > > > > "getHearingDetailsByCaseNoWSReturn");
> > > > >
> > > > > I think OMElement does not include "http://cis.com" as namespace
> because
> > > > > " http://cis.com" is not explicitly declared as a namespace in DOM
> doc.
> > > I
> > > > > searched the interfaces of Document and Element, but cannot find a
> way
> > > to
> > > > > explicitly declare a namespace.
> > > > > I think I need to treat namespace as attribute in DOM. Please
> correct me
> > > if
> > > > > I am wrong.
> > > > >
> > > > > Thus I added one line to declare xmlns as attribute.
> > > > >
> > > > > root.setAttribute("xmlns", " http://cis.com").
> > > > >
> > > > > Is there any other elegant way?
> > > > >
> > > > >
> > > > > 2. Do you have a good way to remove all null elements like
> <duration/>?
> > > The
> > > > > original DOM Element also contains other null elements which
> contains no
> > > > > value.
> > > > >
> > > > >
> > > > >
> > > > > Regards,
> > > > > Xinjun
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > > > > Hi Xinjun,
> > > > > >
> > > > > > How did u create the DOM element that is to be converted to OM? If
> you
> > > > > > read it from a file you MUST make sure you the
> DocumentBuilderFactory
> > > > > > instance that you use to create the DocumentBuilder instance that
> > > > > > parses the xml is *namspaceAware*.
> > > > > >
> > > > > > Please see here[1] for an example.
> > > > > >
> > > > > > Thanks,
> > > > > > Ruchith
> > > > > >
> > > > > > [1] http://rafb.net/p/DDc2NH37.html
> > > > > >
> > > > > >
> > > > > > On 1/10/07, Xinjun Chen < xjchen001@gmail.com> wrote:
> > > > > > > Hi,
> > > > > > >
> > > > > > > I am trying to convert a DOM Element to OMElement using the
> > > following
> > > > > toOM
> > > > > > > code in
> org.apache.axis2.security.util.Axis2Util.
> > > > > > >
> > > > > > >  public static OMElement toOM(Element element) throws Exception
> {
> > > > > > >   try {
> > > > > > >     org.apache.xml.security.Init.init();
> > > > > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > > > > >     XMLUtils.outputDOM (element, os, true);
> > > > > > >
> > > > > > >    ByteArrayInputStream is = new ByteArrayInputStream(
> > > os.toByteArray());
> > > > > > >    XMLStreamReader reader =
> > > > > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > > > > >
> > > > > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > > > > >     builder.setCache(true);
> > > > > > >    return builder.getDocumentElement();
> > > > > > >   } catch (XMLStreamException e) {
> > > > > > >    log.fatal(e.getMessage (), e);
> > > > > > >    throw new Exception("Error when converting from DOM Element
> to
> > > OM.");
> > > > > > >   }
> > > > > > >
> > > > > > > There are two problems with the code:
> > > > > > > 1. I must add the bolded line in the toOM() method.
> > > > > > > 2. This method seems not deal with namespace correctly.
> > > > > > >
> > > > > > > My original DOM Element is as follows:
> > > > > > > <?xml version=" 1.0"
> > > > > > >
> > > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > > > > xmlns="
> > > > > > >
> > > > >
> > >
> http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > >
> > > > > > > But when I use the method to convert the DOM Element into
> OMElement,
> > > it
> > > > > > > reads:
> > > > > > >
> > > > >
> > >
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > > > > >
> > > > >
> > >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > > >
> > > > > > >
> > > > > > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > > > > > >
> > > > > > > After I add the OMElement to a SOAPEnvelope using the following
> > > code,
> > > > > every
> > > > > > > element is qualified with "" namespace which is unexpected.
> > > > > > >
> > > > > > > SOAPFactory fac =
> > > OMAbstractFactory.getSOAP11Factory();
> > > > > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > > > > envelope.getBody().addChild(om);
> > > > > > >
> > > > > > > /*******************************
> > > > > > > Result SOAPEnvelope
> > > > > > > *******************************/
> > > > > > > <?xml version=' 1.0' encoding='utf-8'?>
> > > > > > > <soapenv:Envelope
> > > > > > >  xmlns:soapenv="
> > > > > http://schemas.xmlsoap.org/soap/envelope/ ">
> > > > > > >  <soapenv:Header />
> > > > > > >  <soapenv:Body>
> > > > > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > > >    <hearingDetailsVO xmlns="">
> > > > > > >     <duration xmlns="" />
> > > > > > >     <applicationNo
> xmlns="">sAppNo0</applicationNo>
> > > > > > >    </hearingDetailsVO>
> > > > > > >   </getHearingDetailsByCaseNoWSReturn>
> > > > > > >  </soapenv:Body>
> > > > > > > </soapenv:Envelope>
> > > > > > >
> > > > > > >
> > > > > > > Could anyone tell me how can I solve the problems?
> > > > > > >
> > > > > > >
> > > > > > > Regards,
> > > > > > > Xinjun
> > > > > >
> > > > > >
> > > > > > --
> > > > > > www.ruchith.org
> > > > > > www.wso2.org
> > > > > >
> > > > > >
> > > > >
> > >
> ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail:
> > > > > axis-user-unsubscribe@ws.apache.org
> > > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Paul Fremantle
> > > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > > >
> > > > http://bloglines.com/blog/paulfremantle
> > > > paul@wso2.com
> > > >
> > > > "Oxygenating the Web Service Platform", www.wso2.com
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > axis-user-unsubscribe@ws.apache.org
> > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > Paul Fremantle
> > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> >
> > http://bloglines.com/blog/paulfremantle
> > paul@wso2.com
> >
> > "Oxygenating the Web Service Platform", www.wso2.com
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>


-- 
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Paul,

Thank you for your reply.
Before I chose Castor, I have already looked into JIBX. JIBX also enable
binding for Java collections. But what I understand JIBX databinding is
that, JIBX needs to modify the bytecode. The original class file will be
replaced by the new class file which added some marshalling/unmarshalling
related codes. I have sent an email to Dennis on whether JIBX can separating
the marshalling code from the original class, but did not get response. I
did not find example of using JIBX and keeping the original class unchanged.
Please enlighten me this if you know how to do this. Any comments or
pointers will be helpful.

I also want to use StAX-based binding framework directly if possible.


On 1/12/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> Xinjun
>
> Have you tried some of the databinding frameworks that Axis2 supports?
> Maybe JIBX or XMLBeans, or even ADB would suit you better. The DOM
> approach will be very slow indeed compared to using a STAX based
> binding framework.
>
> The DOM over OM is in axiom-dom-**.jar. This is an implementation of
> DOM that uses Axiom underneath, and so can let you switch between
> them.
>
> Paul
>
> On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi Paul,
> >
> > Thank you for your reply.
> > I am using Castor to create DOM Node, and then convert the DOM Node into
> OM.
> > It seems that Castor does not support AXIOM.
> >
> > I choose Castor marshalling framework because I got the class files from
> my
> > client and I am not supposed to modify the class files. And there are
> some
> > java.util.Map and java.util.Vector inside the class file. It hits me
> that
> > Castor marshalling framework may satisfy both requirements. Do I have
> other
> > options which may satisfy these two requirements?
> >
> > Do you mean if I construct the OM directly I will have control on
> > eliminating the null elements at node creation time?
> > What do you mean there is a version of DOM that uses OM underneath?
> >
> > Thanks.
> >
> > Regards,
> > Xinjun
> >
> >
> >
> > On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
> > > Xinjun
> > >
> > > How are you creating the DOM element? There might be some options to
> > > use OM directly. Firstly, maybe you could just code to OM. Or if you
> > > already have lots of DOM code then there is also a version of DOM that
> > > uses OM underneath.
> > >
> > > Paul
> > >
> > > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > Hi Ruchith,
> > > >
> > > > setNamespaceAware to the original DocumentBuilderFactory solve the
> > problem
> > > > partially.
> > > >
> > > > Now the DOM Element reads:
> > > > <?xml version="1.0"
> > > >   encoding="UTF-8"?>
> > > > <getHearingDetailsByCaseNoWSReturn
> > xmlns="http://cis.com">
> > > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > > >       <duration/>
> > > >       <applicationNo>sAppNo0</applicationNo>
> > > >     </hearingDetailsVO>
> > > > </getHearingDetailsByCaseNoWSReturn>
> > > >
> > > > But the OMElement reads:
> > > >
> > > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > > >       <duration/>
> > > >       <applicationNo>sAppNo0</applicationNo>
> > > >     </hearingDetailsVO>
> > > > </getHearingDetailsByCaseNoWSReturn>
> > > >
> > > > Observations:
> > > > 1. After I setNamespaceAware to the original DOM
> DocumentBuilderFactory,
> > the
> > > > inner element <hearingDetailsVO> gets correct namespace. But root
> > element
> > > > <getHearingDetailsByCaseNoWSReturn> does not. The
> > namespace
> > > > of <getHearingDetailsByCaseNoWSReturn> is lost. I
> > created
> > > > this element in the following way:
> > > >
> > > > DocumentBuilderFactory dbf =
> > > > DocumentBuilderFactory.newInstance();
> > > > dbf.setNamespaceAware(true);
> > > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > > Element root = doc.createElementNS(" http://cis.com",
> > > > "getHearingDetailsByCaseNoWSReturn");
> > > >
> > > > I think OMElement does not include "http://cis.com" as namespace
> because
> > > > " http://cis.com" is not explicitly declared as a namespace in DOM
> doc.
> > I
> > > > searched the interfaces of Document and Element, but cannot find a
> way
> > to
> > > > explicitly declare a namespace.
> > > > I think I need to treat namespace as attribute in DOM. Please
> correct me
> > if
> > > > I am wrong.
> > > >
> > > > Thus I added one line to declare xmlns as attribute.
> > > >
> > > > root.setAttribute("xmlns", " http://cis.com").
> > > >
> > > > Is there any other elegant way?
> > > >
> > > >
> > > > 2. Do you have a good way to remove all null elements like
> <duration/>?
> > The
> > > > original DOM Element also contains other null elements which
> contains no
> > > > value.
> > > >
> > > >
> > > >
> > > > Regards,
> > > > Xinjun
> > > >
> > > >
> > > >
> > > >
> > > > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > > > Hi Xinjun,
> > > > >
> > > > > How did u create the DOM element that is to be converted to OM? If
> you
> > > > > read it from a file you MUST make sure you the
> DocumentBuilderFactory
> > > > > instance that you use to create the DocumentBuilder instance that
> > > > > parses the xml is *namspaceAware*.
> > > > >
> > > > > Please see here[1] for an example.
> > > > >
> > > > > Thanks,
> > > > > Ruchith
> > > > >
> > > > > [1] http://rafb.net/p/DDc2NH37.html
> > > > >
> > > > >
> > > > > On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I am trying to convert a DOM Element to OMElement using the
> > following
> > > > toOM
> > > > > > code in  org.apache.axis2.security.util.Axis2Util.
> > > > > >
> > > > > >  public static OMElement toOM(Element element) throws Exception
> {
> > > > > >   try {
> > > > > >     org.apache.xml.security.Init.init();
> > > > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > > > >    XMLUtils.outputDOM (element, os, true);
> > > > > >
> > > > > >    ByteArrayInputStream is = new ByteArrayInputStream(
> > os.toByteArray());
> > > > > >    XMLStreamReader reader =
> > > > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > > > >
> > > > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > > > >    builder.setCache(true);
> > > > > >    return builder.getDocumentElement();
> > > > > >   } catch (XMLStreamException e) {
> > > > > >    log.fatal(e.getMessage (), e);
> > > > > >    throw new Exception("Error when converting from DOM Element
> to
> > OM.");
> > > > > >   }
> > > > > >
> > > > > > There are two problems with the code:
> > > > > > 1. I must add the bolded line in the toOM() method.
> > > > > > 2. This method seems not deal with namespace correctly.
> > > > > >
> > > > > > My original DOM Element is as follows:
> > > > > > <?xml version="1.0"
> > > > > >
> > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > > > xmlns="
> > > > > >
> > > >
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > > But when I use the method to convert the DOM Element into
> OMElement,
> > it
> > > > > > reads:
> > > > > >
> > > >
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > > > >
> > > >
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > > >
> > > > > >
> > > > > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > > > > >
> > > > > > After I add the OMElement to a SOAPEnvelope using the following
> > code,
> > > > every
> > > > > > element is qualified with "" namespace which is unexpected.
> > > > > >
> > > > > > SOAPFactory fac =
> > OMAbstractFactory.getSOAP11Factory();
> > > > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > > > envelope.getBody().addChild(om);
> > > > > >
> > > > > > /*******************************
> > > > > > Result SOAPEnvelope
> > > > > > *******************************/
> > > > > > <?xml version=' 1.0' encoding='utf-8'?>
> > > > > > <soapenv:Envelope
> > > > > >  xmlns:soapenv="
> > > > http://schemas.xmlsoap.org/soap/envelope/ ">
> > > > > >  <soapenv:Header />
> > > > > >  <soapenv:Body>
> > > > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > > >    <hearingDetailsVO xmlns="">
> > > > > >     <duration xmlns="" />
> > > > > >     <applicationNo xmlns="">sAppNo0</applicationNo>
> > > > > >    </hearingDetailsVO>
> > > > > >   </getHearingDetailsByCaseNoWSReturn>
> > > > > >  </soapenv:Body>
> > > > > > </soapenv:Envelope>
> > > > > >
> > > > > >
> > > > > > Could anyone tell me how can I solve the problems?
> > > > > >
> > > > > >
> > > > > > Regards,
> > > > > > Xinjun
> > > > >
> > > > >
> > > > > --
> > > > > www.ruchith.org
> > > > > www.wso2.org
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > axis-user-unsubscribe@ws.apache.org
> > > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Paul Fremantle
> > > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> > >
> > > http://bloglines.com/blog/paulfremantle
> > > paul@wso2.com
> > >
> > > "Oxygenating the Web Service Platform", www.wso2.com
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> >
>
>
> --
> Paul Fremantle
> VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
>
> http://bloglines.com/blog/paulfremantle
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Paul Fremantle <pz...@gmail.com>.
Xinjun

Have you tried some of the databinding frameworks that Axis2 supports?
Maybe JIBX or XMLBeans, or even ADB would suit you better. The DOM
approach will be very slow indeed compared to using a STAX based
binding framework.

The DOM over OM is in axiom-dom-**.jar. This is an implementation of
DOM that uses Axiom underneath, and so can let you switch between
them.

Paul

On 1/12/07, Xinjun Chen <xj...@gmail.com> wrote:
> Hi Paul,
>
> Thank you for your reply.
> I am using Castor to create DOM Node, and then convert the DOM Node into OM.
> It seems that Castor does not support AXIOM.
>
> I choose Castor marshalling framework because I got the class files from my
> client and I am not supposed to modify the class files. And there are some
> java.util.Map and java.util.Vector inside the class file. It hits me that
> Castor marshalling framework may satisfy both requirements. Do I have other
> options which may satisfy these two requirements?
>
> Do you mean if I construct the OM directly I will have control on
> eliminating the null elements at node creation time?
> What do you mean there is a version of DOM that uses OM underneath?
>
> Thanks.
>
> Regards,
> Xinjun
>
>
>
> On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
> > Xinjun
> >
> > How are you creating the DOM element? There might be some options to
> > use OM directly. Firstly, maybe you could just code to OM. Or if you
> > already have lots of DOM code then there is also a version of DOM that
> > uses OM underneath.
> >
> > Paul
> >
> > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > Hi Ruchith,
> > >
> > > setNamespaceAware to the original DocumentBuilderFactory solve the
> problem
> > > partially.
> > >
> > > Now the DOM Element reads:
> > > <?xml version="1.0"
> > >   encoding="UTF-8"?>
> > > <getHearingDetailsByCaseNoWSReturn
> xmlns="http://cis.com">
> > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > >       <duration/>
> > >       <applicationNo>sAppNo0</applicationNo>
> > >     </hearingDetailsVO>
> > > </getHearingDetailsByCaseNoWSReturn>
> > >
> > > But the OMElement reads:
> > >
> > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > >       <duration/>
> > >       <applicationNo>sAppNo0</applicationNo>
> > >     </hearingDetailsVO>
> > > </getHearingDetailsByCaseNoWSReturn>
> > >
> > > Observations:
> > > 1. After I setNamespaceAware to the original DOM DocumentBuilderFactory,
> the
> > > inner element <hearingDetailsVO> gets correct namespace. But root
> element
> > > <getHearingDetailsByCaseNoWSReturn> does not. The
> namespace
> > > of <getHearingDetailsByCaseNoWSReturn> is lost. I
> created
> > > this element in the following way:
> > >
> > > DocumentBuilderFactory dbf =
> > > DocumentBuilderFactory.newInstance();
> > > dbf.setNamespaceAware(true);
> > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > Element root = doc.createElementNS(" http://cis.com",
> > > "getHearingDetailsByCaseNoWSReturn");
> > >
> > > I think OMElement does not include "http://cis.com" as namespace because
> > > " http://cis.com" is not explicitly declared as a namespace in DOM doc.
> I
> > > searched the interfaces of Document and Element, but cannot find a way
> to
> > > explicitly declare a namespace.
> > > I think I need to treat namespace as attribute in DOM. Please correct me
> if
> > > I am wrong.
> > >
> > > Thus I added one line to declare xmlns as attribute.
> > >
> > > root.setAttribute("xmlns", " http://cis.com").
> > >
> > > Is there any other elegant way?
> > >
> > >
> > > 2. Do you have a good way to remove all null elements like <duration/>?
> The
> > > original DOM Element also contains other null elements which contains no
> > > value.
> > >
> > >
> > >
> > > Regards,
> > > Xinjun
> > >
> > >
> > >
> > >
> > > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > > Hi Xinjun,
> > > >
> > > > How did u create the DOM element that is to be converted to OM? If you
> > > > read it from a file you MUST make sure you the DocumentBuilderFactory
> > > > instance that you use to create the DocumentBuilder instance that
> > > > parses the xml is *namspaceAware*.
> > > >
> > > > Please see here[1] for an example.
> > > >
> > > > Thanks,
> > > > Ruchith
> > > >
> > > > [1] http://rafb.net/p/DDc2NH37.html
> > > >
> > > >
> > > > On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > > Hi,
> > > > >
> > > > > I am trying to convert a DOM Element to OMElement using the
> following
> > > toOM
> > > > > code in  org.apache.axis2.security.util.Axis2Util.
> > > > >
> > > > >  public static OMElement toOM(Element element) throws Exception {
> > > > >   try {
> > > > >     org.apache.xml.security.Init.init();
> > > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > > >    XMLUtils.outputDOM (element, os, true);
> > > > >
> > > > >    ByteArrayInputStream is = new ByteArrayInputStream(
> os.toByteArray());
> > > > >    XMLStreamReader reader =
> > > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > > >
> > > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > > >    builder.setCache(true);
> > > > >    return builder.getDocumentElement();
> > > > >   } catch (XMLStreamException e) {
> > > > >    log.fatal(e.getMessage (), e);
> > > > >    throw new Exception("Error when converting from DOM Element to
> OM.");
> > > > >   }
> > > > >
> > > > > There are two problems with the code:
> > > > > 1. I must add the bolded line in the toOM() method.
> > > > > 2. This method seems not deal with namespace correctly.
> > > > >
> > > > > My original DOM Element is as follows:
> > > > > <?xml version="1.0"
> > > > >
> encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > > xmlns="
> > > > >
> > >
> http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > >
> > > > > But when I use the method to convert the DOM Element into OMElement,
> it
> > > > > reads:
> > > > >
> > >
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > > >
> > >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > > >
> > > > >
> > > > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > > > >
> > > > > After I add the OMElement to a SOAPEnvelope using the following
> code,
> > > every
> > > > > element is qualified with "" namespace which is unexpected.
> > > > >
> > > > > SOAPFactory fac =
> OMAbstractFactory.getSOAP11Factory();
> > > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > > envelope.getBody().addChild(om);
> > > > >
> > > > > /*******************************
> > > > > Result SOAPEnvelope
> > > > > *******************************/
> > > > > <?xml version=' 1.0' encoding='utf-8'?>
> > > > > <soapenv:Envelope
> > > > >  xmlns:soapenv="
> > > http://schemas.xmlsoap.org/soap/envelope/ ">
> > > > >  <soapenv:Header />
> > > > >  <soapenv:Body>
> > > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > > >    <hearingDetailsVO xmlns="">
> > > > >     <duration xmlns="" />
> > > > >     <applicationNo xmlns="">sAppNo0</applicationNo>
> > > > >    </hearingDetailsVO>
> > > > >   </getHearingDetailsByCaseNoWSReturn>
> > > > >  </soapenv:Body>
> > > > > </soapenv:Envelope>
> > > > >
> > > > >
> > > > > Could anyone tell me how can I solve the problems?
> > > > >
> > > > >
> > > > > Regards,
> > > > > Xinjun
> > > >
> > > >
> > > > --
> > > > www.ruchith.org
> > > > www.wso2.org
> > > >
> > > >
> > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > axis-user-unsubscribe@ws.apache.org
> > > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > Paul Fremantle
> > VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
> >
> > http://bloglines.com/blog/paulfremantle
> > paul@wso2.com
> >
> > "Oxygenating the Web Service Platform", www.wso2.com
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>


-- 
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Paul,

Thank you for your reply.
I am using Castor to create DOM Node, and then convert the DOM Node into OM.
It seems that Castor does not support AXIOM.

I choose Castor marshalling framework because I got the class files from my
client and I am not supposed to modify the class files. And there are some
java.util.Map and java.util.Vector inside the class file. It hits me that
Castor marshalling framework may satisfy both requirements. Do I have other
options which may satisfy these two requirements?

Do you mean if I construct the OM directly I will have control on
eliminating the null elements at node creation time?
What do you mean there is *a version of DOM that uses OM underneath*?

Thanks.

Regards,
Xinjun


On 1/11/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> Xinjun
>
> How are you creating the DOM element? There might be some options to
> use OM directly. Firstly, maybe you could just code to OM. Or if you
> already have lots of DOM code then there is also a version of DOM that
> uses OM underneath.
>
> Paul
>
> On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi Ruchith,
> >
> > setNamespaceAware to the original DocumentBuilderFactory solve the
> problem
> > partially.
> >
> > Now the DOM Element reads:
> > <?xml version="1.0"
> >   encoding="UTF-8"?>
> > <getHearingDetailsByCaseNoWSReturn xmlns="http://cis.com">
> >     <hearingDetailsVO xmlns="http://vo.cis.com">
> >       <duration/>
> >       <applicationNo>sAppNo0</applicationNo>
> >     </hearingDetailsVO>
> > </getHearingDetailsByCaseNoWSReturn>
> >
> > But the OMElement reads:
> >
> > <getHearingDetailsByCaseNoWSReturn xmlns="">
> >     <hearingDetailsVO xmlns="http://vo.cis.com">
> >       <duration/>
> >       <applicationNo>sAppNo0</applicationNo>
> >     </hearingDetailsVO>
> > </getHearingDetailsByCaseNoWSReturn>
> >
> > Observations:
> > 1. After I setNamespaceAware to the original DOM DocumentBuilderFactory,
> the
> > inner element <hearingDetailsVO> gets correct namespace. But root
> element
> > <getHearingDetailsByCaseNoWSReturn> does not. The namespace
> > of <getHearingDetailsByCaseNoWSReturn> is lost. I created
> > this element in the following way:
> >
> > DocumentBuilderFactory dbf =
> > DocumentBuilderFactory.newInstance();
> > dbf.setNamespaceAware(true);
> > Document doc = dbf.newDocumentBuilder().newDocument();
> > Element root = doc.createElementNS(" http://cis.com",
> > "getHearingDetailsByCaseNoWSReturn");
> >
> > I think OMElement does not include "http://cis.com" as namespace because
> > "http://cis.com" is not explicitly declared as a namespace in DOM doc. I
> > searched the interfaces of Document and Element, but cannot find a way
> to
> > explicitly declare a namespace.
> > I think I need to treat namespace as attribute in DOM. Please correct me
> if
> > I am wrong.
> >
> > Thus I added one line to declare xmlns as attribute.
> >
> > root.setAttribute("xmlns", "http://cis.com").
> >
> > Is there any other elegant way?
> >
> >
> > 2. Do you have a good way to remove all null elements like <duration/>?
> The
> > original DOM Element also contains other null elements which contains no
> > value.
> >
> >
> >
> > Regards,
> > Xinjun
> >
> >
> >
> >
> > On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > > Hi Xinjun,
> > >
> > > How did u create the DOM element that is to be converted to OM? If you
> > > read it from a file you MUST make sure you the DocumentBuilderFactory
> > > instance that you use to create the DocumentBuilder instance that
> > > parses the xml is *namspaceAware*.
> > >
> > > Please see here[1] for an example.
> > >
> > > Thanks,
> > > Ruchith
> > >
> > > [1] http://rafb.net/p/DDc2NH37.html
> > >
> > >
> > > On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > > Hi,
> > > >
> > > > I am trying to convert a DOM Element to OMElement using the
> following
> > toOM
> > > > code in  org.apache.axis2.security.util.Axis2Util.
> > > >
> > > >  public static OMElement toOM(Element element) throws Exception {
> > > >   try {
> > > >    org.apache.xml.security.Init.init();
> > > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > > >    XMLUtils.outputDOM (element, os, true);
> > > >
> > > >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray
> ());
> > > >    XMLStreamReader reader =
> > > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > > >
> > > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > > >    builder.setCache(true);
> > > >    return builder.getDocumentElement();
> > > >   } catch (XMLStreamException e) {
> > > >    log.fatal(e.getMessage (), e);
> > > >    throw new Exception("Error when converting from DOM Element to
> OM.");
> > > >   }
> > > >
> > > > There are two problems with the code:
> > > > 1. I must add the bolded line in the toOM() method.
> > > > 2. This method seems not deal with namespace correctly.
> > > >
> > > > My original DOM Element is as follows:
> > > > <?xml version="1.0"
> > > > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > > xmlns="
> > > >
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > >
> > > > But when I use the method to convert the DOM Element into OMElement,
> it
> > > > reads:
> > > >
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > > >
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > > >
> > > >
> > > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > > >
> > > > After I add the OMElement to a SOAPEnvelope using the following
> code,
> > every
> > > > element is qualified with "" namespace which is unexpected.
> > > >
> > > > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > > envelope.getBody().addChild(om);
> > > >
> > > > /*******************************
> > > > Result SOAPEnvelope
> > > > *******************************/
> > > > <?xml version='1.0' encoding='utf-8'?>
> > > > <soapenv:Envelope
> > > >  xmlns:soapenv="
> > http://schemas.xmlsoap.org/soap/envelope/">
> > > >  <soapenv:Header />
> > > >  <soapenv:Body>
> > > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > > >    <hearingDetailsVO xmlns="">
> > > >     <duration xmlns="" />
> > > >     <applicationNo xmlns="">sAppNo0</applicationNo>
> > > >    </hearingDetailsVO>
> > > >   </getHearingDetailsByCaseNoWSReturn>
> > > >  </soapenv:Body>
> > > > </soapenv:Envelope>
> > > >
> > > >
> > > > Could anyone tell me how can I solve the problems?
> > > >
> > > >
> > > > Regards,
> > > > Xinjun
> > >
> > >
> > > --
> > > www.ruchith.org
> > > www.wso2.org
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > axis-user-unsubscribe@ws.apache.org
> > > For additional commands, e-mail: axis-user-help@ws.apache.org
> > >
> > >
> >
> >
>
>
> --
> Paul Fremantle
> VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
>
> http://bloglines.com/blog/paulfremantle
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Paul Fremantle <pz...@gmail.com>.
Xinjun

How are you creating the DOM element? There might be some options to
use OM directly. Firstly, maybe you could just code to OM. Or if you
already have lots of DOM code then there is also a version of DOM that
uses OM underneath.

Paul

On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> Hi Ruchith,
>
> setNamespaceAware to the original DocumentBuilderFactory solve the problem
> partially.
>
> Now the DOM Element reads:
> <?xml version="1.0"
>   encoding="UTF-8"?>
> <getHearingDetailsByCaseNoWSReturn xmlns="http://cis.com">
>     <hearingDetailsVO xmlns="http://vo.cis.com">
>       <duration/>
>       <applicationNo>sAppNo0</applicationNo>
>     </hearingDetailsVO>
> </getHearingDetailsByCaseNoWSReturn>
>
> But the OMElement reads:
>
> <getHearingDetailsByCaseNoWSReturn xmlns="">
>     <hearingDetailsVO xmlns="http://vo.cis.com">
>       <duration/>
>       <applicationNo>sAppNo0</applicationNo>
>     </hearingDetailsVO>
> </getHearingDetailsByCaseNoWSReturn>
>
> Observations:
> 1. After I setNamespaceAware to the original DOM DocumentBuilderFactory, the
> inner element <hearingDetailsVO> gets correct namespace. But root element
> <getHearingDetailsByCaseNoWSReturn> does not. The namespace
> of <getHearingDetailsByCaseNoWSReturn> is lost. I created
> this element in the following way:
>
> DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> Document doc = dbf.newDocumentBuilder().newDocument();
> Element root = doc.createElementNS(" http://cis.com",
> "getHearingDetailsByCaseNoWSReturn");
>
> I think OMElement does not include "http://cis.com" as namespace because
> "http://cis.com" is not explicitly declared as a namespace in DOM doc. I
> searched the interfaces of Document and Element, but cannot find a way to
> explicitly declare a namespace.
> I think I need to treat namespace as attribute in DOM. Please correct me if
> I am wrong.
>
> Thus I added one line to declare xmlns as attribute.
>
> root.setAttribute("xmlns", "http://cis.com").
>
> Is there any other elegant way?
>
>
> 2. Do you have a good way to remove all null elements like <duration/>? The
> original DOM Element also contains other null elements which contains no
> value.
>
>
>
> Regards,
> Xinjun
>
>
>
>
> On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > Hi Xinjun,
> >
> > How did u create the DOM element that is to be converted to OM? If you
> > read it from a file you MUST make sure you the DocumentBuilderFactory
> > instance that you use to create the DocumentBuilder instance that
> > parses the xml is *namspaceAware*.
> >
> > Please see here[1] for an example.
> >
> > Thanks,
> > Ruchith
> >
> > [1] http://rafb.net/p/DDc2NH37.html
> >
> >
> > On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > Hi,
> > >
> > > I am trying to convert a DOM Element to OMElement using the following
> toOM
> > > code in  org.apache.axis2.security.util.Axis2Util.
> > >
> > >  public static OMElement toOM(Element element) throws Exception {
> > >   try {
> > >    org.apache.xml.security.Init.init();
> > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > >    XMLUtils.outputDOM (element, os, true);
> > >
> > >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
> > >    XMLStreamReader reader =
> > > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > >
> > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > >    builder.setCache(true);
> > >    return builder.getDocumentElement();
> > >   } catch (XMLStreamException e) {
> > >    log.fatal(e.getMessage (), e);
> > >    throw new Exception("Error when converting from DOM Element to OM.");
> > >   }
> > >
> > > There are two problems with the code:
> > > 1. I must add the bolded line in the toOM() method.
> > > 2. This method seems not deal with namespace correctly.
> > >
> > > My original DOM Element is as follows:
> > > <?xml version="1.0"
> > > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > > xmlns="
> > >
> http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > >
> > > But when I use the method to convert the DOM Element into OMElement, it
> > > reads:
> > >
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> > >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> > >
> > >
> > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > >
> > > After I add the OMElement to a SOAPEnvelope using the following code,
> every
> > > element is qualified with "" namespace which is unexpected.
> > >
> > > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > envelope.getBody().addChild(om);
> > >
> > > /*******************************
> > > Result SOAPEnvelope
> > > *******************************/
> > > <?xml version='1.0' encoding='utf-8'?>
> > > <soapenv:Envelope
> > >  xmlns:soapenv="
> http://schemas.xmlsoap.org/soap/envelope/">
> > >  <soapenv:Header />
> > >  <soapenv:Body>
> > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > >    <hearingDetailsVO xmlns="">
> > >     <duration xmlns="" />
> > >     <applicationNo xmlns="">sAppNo0</applicationNo>
> > >    </hearingDetailsVO>
> > >   </getHearingDetailsByCaseNoWSReturn>
> > >  </soapenv:Body>
> > > </soapenv:Envelope>
> > >
> > >
> > > Could anyone tell me how can I solve the problems?
> > >
> > >
> > > Regards,
> > > Xinjun
> >
> >
> > --
> > www.ruchith.org
> > www.wso2.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>


-- 
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Ruchith,

Thanks for the info.
I think the codes mentioned in [1] has the same effect as root.setAttribute().


Regards,
Xinjun

On 1/12/07, Ruchith Fernando <ru...@gmail.com> wrote:
>
> Hi Xinjun,
>
> To make sure you have the namespace declaration properly you have to
> add the namespace attribute. Please see here [1].
>
> Thanks,
> Ruchith
>
> [1]
> http://www.ftponline.com/javapro/2003_06/online/namespace_kjones_06_23_03/
>
> On 1/12/07, Ruchith Fernando <ru...@gmail.com> wrote:
> > Hi Xinjun,
> >
> > On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > > Hi Ruchith,
> > >
> > > setNamespaceAware to the original DocumentBuilderFactory solve the
> problem
> > > partially.
> > >
> > > Now the DOM Element reads:
> > > <?xml version="1.0"
> > >   encoding="UTF-8"?>
> > > <getHearingDetailsByCaseNoWSReturn xmlns="http://cis.com">
> > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > >       <duration/>
> > >       <applicationNo>sAppNo0</applicationNo>
> > >     </hearingDetailsVO>
> > > </getHearingDetailsByCaseNoWSReturn>
> > >
> > > But the OMElement reads:
> > >
> > > <getHearingDetailsByCaseNoWSReturn xmlns="">
> > >     <hearingDetailsVO xmlns="http://vo.cis.com">
> > >       <duration/>
> > >       <applicationNo>sAppNo0</applicationNo>
> > >     </hearingDetailsVO>
> > > </getHearingDetailsByCaseNoWSReturn>
> >
> > IMHO the issue here is with the XMLUtils#outputDOM() method :-)
> >
> > It doesn't serialize the root element's namespaces properly.
> >
> > Please see here [1]
> >
> > >
> > > Observations:
> > > 1. After I setNamespaceAware to the original DOM
> DocumentBuilderFactory, the
> > > inner element <hearingDetailsVO> gets correct namespace. But root
> element
> > > <getHearingDetailsByCaseNoWSReturn> does not. The namespace
> > > of <getHearingDetailsByCaseNoWSReturn> is lost. I created
> > > this element in the following way:
> > >
> > > DocumentBuilderFactory dbf =
> > > DocumentBuilderFactory.newInstance();
> > > dbf.setNamespaceAware(true);
> > > Document doc = dbf.newDocumentBuilder().newDocument();
> > > Element root = doc.createElementNS(" http://cis.com",
> > > "getHearingDetailsByCaseNoWSReturn");
> > >
> > > I think OMElement does not include "http://cis.com" as namespace
> because
> > > "http://cis.com" is not explicitly declared as a namespace in DOM doc.
> I
> > > searched the interfaces of Document and Element, but cannot find a way
> to
> > > explicitly declare a namespace.
> > > I think I need to treat namespace as attribute in DOM. Please correct
> me if
> > > I am wrong.
> > >
> > > Thus I added one line to declare xmlns as attribute.
> > >
> > > root.setAttribute("xmlns", "http://cis.com").
> > >
> > > Is there any other elegant way?
> > >
> > >
> > > 2. Do you have a good way to remove all null elements like
> <duration/>? The
> > > original DOM Element also contains other null elements which contains
> no
> > > value.
> >
> > Hmm ... I'm sorry I don't know any shortcut to do that.
> >
> > Thanks,
> > Ruchith
> >
> > [1] http://rafb.net/p/dXERq036.html
> > --
> > www.ruchith.org
> > www.wso2.org
> >
>
>
> --
> www.ruchith.org
> www.wso2.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Xinjun,

To make sure you have the namespace declaration properly you have to
add the namespace attribute. Please see here [1].

Thanks,
Ruchith

[1] http://www.ftponline.com/javapro/2003_06/online/namespace_kjones_06_23_03/

On 1/12/07, Ruchith Fernando <ru...@gmail.com> wrote:
> Hi Xinjun,
>
> On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi Ruchith,
> >
> > setNamespaceAware to the original DocumentBuilderFactory solve the problem
> > partially.
> >
> > Now the DOM Element reads:
> > <?xml version="1.0"
> >   encoding="UTF-8"?>
> > <getHearingDetailsByCaseNoWSReturn xmlns="http://cis.com">
> >     <hearingDetailsVO xmlns="http://vo.cis.com">
> >       <duration/>
> >       <applicationNo>sAppNo0</applicationNo>
> >     </hearingDetailsVO>
> > </getHearingDetailsByCaseNoWSReturn>
> >
> > But the OMElement reads:
> >
> > <getHearingDetailsByCaseNoWSReturn xmlns="">
> >     <hearingDetailsVO xmlns="http://vo.cis.com">
> >       <duration/>
> >       <applicationNo>sAppNo0</applicationNo>
> >     </hearingDetailsVO>
> > </getHearingDetailsByCaseNoWSReturn>
>
> IMHO the issue here is with the XMLUtils#outputDOM() method :-)
>
> It doesn't serialize the root element's namespaces properly.
>
> Please see here [1]
>
> >
> > Observations:
> > 1. After I setNamespaceAware to the original DOM DocumentBuilderFactory, the
> > inner element <hearingDetailsVO> gets correct namespace. But root element
> > <getHearingDetailsByCaseNoWSReturn> does not. The namespace
> > of <getHearingDetailsByCaseNoWSReturn> is lost. I created
> > this element in the following way:
> >
> > DocumentBuilderFactory dbf =
> > DocumentBuilderFactory.newInstance();
> > dbf.setNamespaceAware(true);
> > Document doc = dbf.newDocumentBuilder().newDocument();
> > Element root = doc.createElementNS(" http://cis.com",
> > "getHearingDetailsByCaseNoWSReturn");
> >
> > I think OMElement does not include "http://cis.com" as namespace because
> > "http://cis.com" is not explicitly declared as a namespace in DOM doc. I
> > searched the interfaces of Document and Element, but cannot find a way to
> > explicitly declare a namespace.
> > I think I need to treat namespace as attribute in DOM. Please correct me if
> > I am wrong.
> >
> > Thus I added one line to declare xmlns as attribute.
> >
> > root.setAttribute("xmlns", "http://cis.com").
> >
> > Is there any other elegant way?
> >
> >
> > 2. Do you have a good way to remove all null elements like <duration/>? The
> > original DOM Element also contains other null elements which contains no
> > value.
>
> Hmm ... I'm sorry I don't know any shortcut to do that.
>
> Thanks,
> Ruchith
>
> [1] http://rafb.net/p/dXERq036.html
> --
> www.ruchith.org
> www.wso2.org
>


-- 
www.ruchith.org
www.wso2.org

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Xinjun,

On 1/11/07, Xinjun Chen <xj...@gmail.com> wrote:
> Hi Ruchith,
>
> setNamespaceAware to the original DocumentBuilderFactory solve the problem
> partially.
>
> Now the DOM Element reads:
> <?xml version="1.0"
>   encoding="UTF-8"?>
> <getHearingDetailsByCaseNoWSReturn xmlns="http://cis.com">
>     <hearingDetailsVO xmlns="http://vo.cis.com">
>       <duration/>
>       <applicationNo>sAppNo0</applicationNo>
>     </hearingDetailsVO>
> </getHearingDetailsByCaseNoWSReturn>
>
> But the OMElement reads:
>
> <getHearingDetailsByCaseNoWSReturn xmlns="">
>     <hearingDetailsVO xmlns="http://vo.cis.com">
>       <duration/>
>       <applicationNo>sAppNo0</applicationNo>
>     </hearingDetailsVO>
> </getHearingDetailsByCaseNoWSReturn>

IMHO the issue here is with the XMLUtils#outputDOM() method :-)

It doesn't serialize the root element's namespaces properly.

Please see here [1]

>
> Observations:
> 1. After I setNamespaceAware to the original DOM DocumentBuilderFactory, the
> inner element <hearingDetailsVO> gets correct namespace. But root element
> <getHearingDetailsByCaseNoWSReturn> does not. The namespace
> of <getHearingDetailsByCaseNoWSReturn> is lost. I created
> this element in the following way:
>
> DocumentBuilderFactory dbf =
> DocumentBuilderFactory.newInstance();
> dbf.setNamespaceAware(true);
> Document doc = dbf.newDocumentBuilder().newDocument();
> Element root = doc.createElementNS(" http://cis.com",
> "getHearingDetailsByCaseNoWSReturn");
>
> I think OMElement does not include "http://cis.com" as namespace because
> "http://cis.com" is not explicitly declared as a namespace in DOM doc. I
> searched the interfaces of Document and Element, but cannot find a way to
> explicitly declare a namespace.
> I think I need to treat namespace as attribute in DOM. Please correct me if
> I am wrong.
>
> Thus I added one line to declare xmlns as attribute.
>
> root.setAttribute("xmlns", "http://cis.com").
>
> Is there any other elegant way?
>
>
> 2. Do you have a good way to remove all null elements like <duration/>? The
> original DOM Element also contains other null elements which contains no
> value.

Hmm ... I'm sorry I don't know any shortcut to do that.

Thanks,
Ruchith

[1] http://rafb.net/p/dXERq036.html
-- 
www.ruchith.org
www.wso2.org

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Ruchith,

setNamespaceAware to the original DocumentBuilderFactory solve the problem
partially.

Now the DOM Element reads:
<?xml version="1.0"
  encoding="UTF-8"?>
<getHearingDetailsByCaseNoWSReturn *xmlns="http://cis.com"*>
    <hearingDetailsVO *xmlns="http://vo.cis.com"*>
      <duration/>
      <applicationNo>sAppNo0</applicationNo>
    </hearingDetailsVO>
</getHearingDetailsByCaseNoWSReturn>

But the OMElement reads:
 <getHearingDetailsByCaseNoWSReturn *xmlns=""*>
    <hearingDetailsVO *xmlns="http://vo.cis.com"*>
      <duration/>
      <applicationNo>sAppNo0</applicationNo>
    </hearingDetailsVO>
</getHearingDetailsByCaseNoWSReturn>

Observations:
1. After I setNamespaceAware to the original DOM DocumentBuilderFactory, the
inner element <hearingDetailsVO> gets correct namespace. But root
element <getHearingDetailsByCaseNoWSReturn> does not. The namespace of
<getHearingDetailsByCaseNoWSReturn> is lost. I created this element in the
following way:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
Element root = doc.createElementNS("http://cis.com",
"getHearingDetailsByCaseNoWSReturn");

I think OMElement does not include "http://cis.com" as namespace because "
http://cis.com" is not explicitly declared as a namespace in DOM doc. I
searched the interfaces of Document and Element, but cannot find a way to
explicitly declare a namespace.
I think I need to treat namespace as attribute in DOM. Please correct me if
I am wrong.

Thus I added one line to declare xmlns as attribute.

root.setAttribute("xmlns", "http://cis.com").

Is there any other elegant way?


2. Do you have a good way to remove all null elements like <duration/>? The
original DOM Element also contains other null elements which contains no
value.



Regards,
Xinjun




On 1/10/07, Ruchith Fernando <ru...@gmail.com> wrote:
>
> Hi Xinjun,
>
> How did u create the DOM element that is to be converted to OM? If you
> read it from a file you MUST make sure you the DocumentBuilderFactory
> instance that you use to create the DocumentBuilder instance that
> parses the xml is *namspaceAware*.
>
> Please see here[1] for an example.
>
> Thanks,
> Ruchith
>
> [1] http://rafb.net/p/DDc2NH37.html
>
>
> On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > Hi,
> >
> > I am trying to convert a DOM Element to OMElement using the following
> toOM
> > code in  org.apache.axis2.security.util.Axis2Util.
> >
> >  public static OMElement toOM(Element element) throws Exception {
> >   try {
> >    org.apache.xml.security.Init.init();
> >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> >    XMLUtils.outputDOM (element, os, true);
> >
> >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
> >    XMLStreamReader reader =
> > XMLInputFactory.newInstance().createXMLStreamReader(is);
> >
> >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> >    builder.setCache(true);
> >    return builder.getDocumentElement();
> >   } catch (XMLStreamException e) {
> >    log.fatal(e.getMessage(), e);
> >    throw new Exception("Error when converting from DOM Element to OM.");
> >   }
> >
> > There are two problems with the code:
> > 1. I must add the bolded line in the toOM() method.
> > 2. This method seems not deal with namespace correctly.
> >
> > My original DOM Element is as follows:
> > <?xml version="1.0"
> > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > xmlns="
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> >
> > But when I use the method to convert the DOM Element into OMElement, it
> > reads:
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> >
> >
> > It seems that the namespace is ignored by the Axis2Util.toOM().
> >
> > After I add the OMElement to a SOAPEnvelope using the following code,
> every
> > element is qualified with "" namespace which is unexpected.
> >
> > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > OMElement om = Axis2Util.toOM((Element)retNode);
> > envelope.getBody().addChild(om);
> >
> > /*******************************
> > Result SOAPEnvelope
> > *******************************/
> > <?xml version='1.0' encoding='utf-8'?>
> > <soapenv:Envelope
> >  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
> >  <soapenv:Header />
> >  <soapenv:Body>
> >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> >    <hearingDetailsVO xmlns="">
> >     <duration xmlns="" />
> >     <applicationNo xmlns="">sAppNo0</applicationNo>
> >    </hearingDetailsVO>
> >   </getHearingDetailsByCaseNoWSReturn>
> >  </soapenv:Body>
> > </soapenv:Envelope>
> >
> >
> > Could anyone tell me how can I solve the problems?
> >
> >
> > Regards,
> > Xinjun
>
>
> --
> www.ruchith.org
> www.wso2.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Ruchith Fernando <ru...@gmail.com>.
Hi Xinjun,

How did u create the DOM element that is to be converted to OM? If you
read it from a file you MUST make sure you the DocumentBuilderFactory
instance that you use to create the DocumentBuilder instance that
parses the xml is *namspaceAware*.

Please see here[1] for an example.

Thanks,
Ruchith

[1] http://rafb.net/p/DDc2NH37.html


On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> Hi,
>
> I am trying to convert a DOM Element to OMElement using the following toOM
> code in  org.apache.axis2.security.util.Axis2Util.
>
>  public static OMElement toOM(Element element) throws Exception {
>   try {
>    org.apache.xml.security.Init.init();
>    ByteArrayOutputStream os = new ByteArrayOutputStream();
>    XMLUtils.outputDOM (element, os, true);
>
>    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
>    XMLStreamReader reader =
> XMLInputFactory.newInstance().createXMLStreamReader(is);
>
>    StAXOMBuilder builder = new StAXOMBuilder(reader);
>    builder.setCache(true);
>    return builder.getDocumentElement();
>   } catch (XMLStreamException e) {
>    log.fatal(e.getMessage(), e);
>    throw new Exception("Error when converting from DOM Element to OM.");
>   }
>
> There are two problems with the code:
> 1. I must add the bolded line in the toOM() method.
> 2. This method seems not deal with namespace correctly.
>
> My original DOM Element is as follows:
> <?xml version="1.0"
> encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> xmlns="
> http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
>
> But when I use the method to convert the DOM Element into OMElement, it
> reads:
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
>
>
> It seems that the namespace is ignored by the Axis2Util.toOM().
>
> After I add the OMElement to a SOAPEnvelope using the following code, every
> element is qualified with "" namespace which is unexpected.
>
> SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> SOAPEnvelope envelope = fac.getDefaultEnvelope();
> OMElement om = Axis2Util.toOM((Element)retNode);
> envelope.getBody().addChild(om);
>
> /*******************************
> Result SOAPEnvelope
> *******************************/
> <?xml version='1.0' encoding='utf-8'?>
> <soapenv:Envelope
>  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>  <soapenv:Header />
>  <soapenv:Body>
>   <getHearingDetailsByCaseNoWSReturn xmlns="">
>    <hearingDetailsVO xmlns="">
>     <duration xmlns="" />
>     <applicationNo xmlns="">sAppNo0</applicationNo>
>    </hearingDetailsVO>
>   </getHearingDetailsByCaseNoWSReturn>
>  </soapenv:Body>
> </soapenv:Envelope>
>
>
> Could anyone tell me how can I solve the problems?
>
>
> Regards,
> Xinjun


-- 
www.ruchith.org
www.wso2.org

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
Hi Paul,

What do you mean by leading space?
There is no leading space.
The default namespace in the original DOM Element is defined as *xmlns="**
http://cis.com"*
But the OMElement returned after calling Axis2Util.toOM(Element) has no
namespace,
after adding the OMElement to the SOAPBody, every tag is included with *
xmlns=""*.

I believe somehow Axis2Util.toOM(Element) ignored the namespaces.


Regards,
Xinjun

On 1/10/07, Paul Fremantle <pz...@gmail.com> wrote:
>
> Xinjun
>
> Does the namespace really have a leading space as in your email? Maybe
> there is a bug in how that is parsed by StAX?
>
> Paul
>
> On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > I believe conversion between DOM Element and OMElement is quite general.
> > Could anyone suggest a good way to do the conversions correctly?
> >
> >
> >
> > On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > I am trying to convert a DOM Element to OMElement using the following
> toOM
> > code in  org.apache.axis2.security.util.Axis2Util.
> > >
> > >  public static OMElement toOM(Element element) throws Exception {
> > >   try {
> > >    org.apache.xml.security.Init.init();
> > >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> > >    XMLUtils.outputDOM (element, os, true);
> > >
> > >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray
> ());
> > >    XMLStreamReader reader =
> > XMLInputFactory.newInstance().createXMLStreamReader(is);
> > >
> > >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> > >    builder.setCache(true);
> > >    return builder.getDocumentElement();
> > >   } catch (XMLStreamException e) {
> > >    log.fatal(e.getMessage(), e);
> > >    throw new Exception("Error when converting from DOM Element to
> OM.");
> > >   }
> > >
> > > There are two problems with the code:
> > > 1. I must add the bolded line in the toOM() method.
> > > 2. This method seems not deal with namespace correctly.
> > >
> > > My original DOM Element is as follows:
> > > <?xml version="1.0"
> > encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> > xmlns="
> > http://cis.com
> "><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn
> > >
> > >
> > > But when I use the method to convert the DOM Element into OMElement,
> it
> > reads:
> > >
> > <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> >
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
> >
> > >
> > > It seems that the namespace is ignored by the Axis2Util.toOM().
> > >
> > > After I add the OMElement to a SOAPEnvelope using the following code,
> > every element is qualified with "" namespace which is unexpected.
> > >
> > > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > > OMElement om = Axis2Util.toOM((Element)retNode);
> > > envelope.getBody().addChild(om);
> > >
> > > /*******************************
> > > Result SOAPEnvelope
> > > *******************************/
> > > <?xml version='1.0' encoding='utf-8'?>
> > > <soapenv:Envelope
> > >  xmlns:soapenv="
> > http://schemas.xmlsoap.org/soap/envelope/">
> > >  <soapenv:Header />
> > >  <soapenv:Body>
> > >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> > >    <hearingDetailsVO xmlns="">
> > >     <duration xmlns="" />
> > >     <applicationNo xmlns="">sAppNo0</applicationNo>
> > >    </hearingDetailsVO>
> > >   </getHearingDetailsByCaseNoWSReturn>
> > >  </soapenv:Body>
> > > </soapenv:Envelope>
> > >
> > >
> > > Could anyone tell me how can I solve the problems?
> > >
> > >
> > > Regards,
> > > Xinjun
> >
> >
>
>
> --
> Paul Fremantle
> VP/Technology, WSO2 and OASIS WS-RX TC Co-chair
>
> http://bloglines.com/blog/paulfremantle
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Paul Fremantle <pz...@gmail.com>.
Xinjun

Does the namespace really have a leading space as in your email? Maybe
there is a bug in how that is parsed by StAX?

Paul

On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> I believe conversion between DOM Element and OMElement is quite general.
> Could anyone suggest a good way to do the conversions correctly?
>
>
>
> On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am trying to convert a DOM Element to OMElement using the following toOM
> code in  org.apache.axis2.security.util.Axis2Util.
> >
> >  public static OMElement toOM(Element element) throws Exception {
> >   try {
> >    org.apache.xml.security.Init.init();
> >    ByteArrayOutputStream os = new ByteArrayOutputStream();
> >    XMLUtils.outputDOM (element, os, true);
> >
> >    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
> >    XMLStreamReader reader =
> XMLInputFactory.newInstance().createXMLStreamReader(is);
> >
> >    StAXOMBuilder builder = new StAXOMBuilder(reader);
> >    builder.setCache(true);
> >    return builder.getDocumentElement();
> >   } catch (XMLStreamException e) {
> >    log.fatal(e.getMessage(), e);
> >    throw new Exception("Error when converting from DOM Element to OM.");
> >   }
> >
> > There are two problems with the code:
> > 1. I must add the bolded line in the toOM() method.
> > 2. This method seems not deal with namespace correctly.
> >
> > My original DOM Element is as follows:
> > <?xml version="1.0"
> encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn
> xmlns="
> http://cis.com"><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn
> >
> >
> > But when I use the method to convert the DOM Element into OMElement, it
> reads:
> >
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
>
> >
> > It seems that the namespace is ignored by the Axis2Util.toOM().
> >
> > After I add the OMElement to a SOAPEnvelope using the following code,
> every element is qualified with "" namespace which is unexpected.
> >
> > SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> > SOAPEnvelope envelope = fac.getDefaultEnvelope();
> > OMElement om = Axis2Util.toOM((Element)retNode);
> > envelope.getBody().addChild(om);
> >
> > /*******************************
> > Result SOAPEnvelope
> > *******************************/
> > <?xml version='1.0' encoding='utf-8'?>
> > <soapenv:Envelope
> >  xmlns:soapenv="
> http://schemas.xmlsoap.org/soap/envelope/">
> >  <soapenv:Header />
> >  <soapenv:Body>
> >   <getHearingDetailsByCaseNoWSReturn xmlns="">
> >    <hearingDetailsVO xmlns="">
> >     <duration xmlns="" />
> >     <applicationNo xmlns="">sAppNo0</applicationNo>
> >    </hearingDetailsVO>
> >   </getHearingDetailsByCaseNoWSReturn>
> >  </soapenv:Body>
> > </soapenv:Envelope>
> >
> >
> > Could anyone tell me how can I solve the problems?
> >
> >
> > Regards,
> > Xinjun
>
>


-- 
Paul Fremantle
VP/Technology, WSO2 and OASIS WS-RX TC Co-chair

http://bloglines.com/blog/paulfremantle
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] Namespace issue during conversion from DOM Element to OMElement

Posted by Xinjun Chen <xj...@gmail.com>.
I believe conversion between DOM Element and OMElement is quite general.
Could anyone suggest a good way to do the conversions correctly?


On 1/10/07, Xinjun Chen <xj...@gmail.com> wrote:
>
> Hi,
>
> I am trying to convert a DOM Element to OMElement using the following toOM
> code in  org.apache.axis2.security.util.Axis2Util.
>
>  public static OMElement toOM(Element element) throws Exception {
>   try {
> *   org.apache.xml.security.Init.init();
> *   ByteArrayOutputStream os = new ByteArrayOutputStream();
>    XMLUtils.outputDOM (element, os, true);
>
>    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
>    XMLStreamReader reader = XMLInputFactory.newInstance
> ().createXMLStreamReader(is);
>
>    StAXOMBuilder builder = new StAXOMBuilder(reader);
>    builder.setCache(true);
>    return builder.getDocumentElement();
>   } catch (XMLStreamException e) {
>    log.fatal(e.getMessage(), e);
>    throw new Exception("Error when converting from DOM Element to OM.");
>   }
>
> There are two problems with the code:
> 1. I must add the bolded line in the toOM() method.
> 2. This method seems not deal with namespace correctly.
>
> My original DOM Element is as follows:
> <?xml version="1.0" encoding="UTF-8"?><getHearingDetailsByCaseNoWSReturn*xmlns="
> * *http://cis.com"*
> ><hearingDetailsVO><duration/><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn
> >
>
> But when I use the method to convert the DOM Element into OMElement, it
> reads:
> <getHearingDetailsByCaseNoWSReturn><hearingDetailsVO><duration
> /><applicationNo>sAppNo0</applicationNo></hearingDetailsVO></getHearingDetailsByCaseNoWSReturn>
>
> It seems that the namespace is ignored by the Axis2Util.toOM().
>
> After I add the OMElement to a SOAPEnvelope using the following code,
> every element is qualified with "" namespace which is unexpected.
>
> SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
> SOAPEnvelope envelope = fac.getDefaultEnvelope();
> OMElement om = Axis2Util.toOM((Element)retNode);
> envelope.getBody().addChild(om);
>
> /*******************************
> Result SOAPEnvelope
> *******************************/
> <?xml version='1.0' encoding='utf-8'?>
> <soapenv:Envelope
>  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>  <soapenv:Header />
>  <soapenv:Body>
>   <getHearingDetailsByCaseNoWSReturn xmlns="">
>    <hearingDetailsVO xmlns="">
>     <duration xmlns="" />
>     <applicationNo xmlns="">sAppNo0</applicationNo>
>    </hearingDetailsVO>
>   </getHearingDetailsByCaseNoWSReturn>
>  </soapenv:Body>
> </soapenv:Envelope>
>
>
> Could anyone tell me how can I solve the problems?
>
>
> Regards,
> Xinjun
>