Hi!

what jboss version are you using? (we have a patched 4.0.2 with some internal 
optimizations.. ).. 

anyway.. here comes our method for converting the DOM node returned from 
XmlObject.newDomNode() to a SOAPElement

its a bit taken out of context.. so I hope it will help :-)

regards,

/Ole


  | /**
  |     * Creates a SOAPElement from the specified DOM node using the specified 
SOAPFactory
  |     * 
  |     * @param domNode the domNode to create for
  |     * @param factory the SOAPFactory to use for node creation.
  |     * @param isRpc if set to true then the top node will be unqualified
  |     * @return the created SOAPElement, <code>null</code if creation fails.
  |     * @throw Exception on internal errors
  |     */
  | 
  |    public static SOAPElement createSOAPElement(org.w3c.dom.Node domNode, 
SOAPFactory factory, boolean isRpc) throws Exception
  |    {
  |       try
  |       {
  |          if( factory == null ) 
  |              factory = SOAPFactory.newInstance();
  | 
  |          // Test that DOMNode is of type org.w3c.dom.Node.ELEMENT_NODE.
  |          if ((domNode.getNodeType()) != org.w3c.dom.Node.ELEMENT_NODE)
  |             throw new Exception("DOMNode must of type ELEMENT_NODE");
  | 
  |          String prefix = domNode.getPrefix();
  |          String namespaceURI = domNode.getNamespaceURI();
  | 
  |          SOAPElement se;
  |                     if (isRpc || prefix == null || prefix.length() == 0  )
  |                     {
  |                              se = 
factory.createElement(factory.createName(domNode.getLocalName()));
  |                     }
  |                     else
  |                     {
  |               se = factory.createElement(domNode.getLocalName(), prefix, 
namespaceURI);
  |                     }
  | 
  |          if (domNode.hasAttributes())
  |          {
  |             NamedNodeMap DOMAttributes = domNode.getAttributes();
  |             int noOfAttributes = DOMAttributes.getLength();
  |             for (int i = 0; i < noOfAttributes; i++)
  |             {
  |                org.w3c.dom.Node attr = DOMAttributes.item(i);
  | 
  |                prefix = attr.getPrefix();
  |                namespaceURI = attr.getNamespaceURI();
  | 
  |                Name name = prefix == null || prefix.length() == 0 ? 
factory.createName(attr.getLocalName()) : factory
  |                      .createName(attr.getLocalName(), prefix, namespaceURI);
  | 
  |                se.addAttribute(name, attr.getNodeValue());
  |             }
  |          }
  | 
  |          if (domNode.hasChildNodes())
  |          {
  |             NodeList children = domNode.getChildNodes();
  |             for (int i = 0; i < children.getLength(); i++)
  |             {
  |                org.w3c.dom.Node child = children.item(i);
  | 
  |                switch (child.getNodeType())
  |                {
  |                   case org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE:
  |                      break;
  | 
  |                   case org.w3c.dom.Node.DOCUMENT_TYPE_NODE:
  |                      break;
  | 
  |                   case org.w3c.dom.Node.COMMENT_NODE:
  |                      break;
  | 
  |                   case org.w3c.dom.Node.CDATA_SECTION_NODE:
  | 
  |                   case org.w3c.dom.Node.TEXT_NODE:
  |                   {
  |                      if (children.getLength() == 1)
  |                         se.addTextNode(child.getNodeValue());
  |                      break;
  |                   }
  | 
  |                   default:
  |                   {
  |                      se.addChildElement(createSOAPElement(child, factory));
  |                   }
  |                }
  | 
  |             }// end of for
  |          }// end of if
  | 
  |          return se;
  |       }
  |       catch (Exception e)
  |       {
  |               e.printStackTrace();
  |          throw new Exception("Failed to create SOAP element from DOM node", 
e);
  |       }
  |    }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3912046#3912046

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3912046


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to