axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brown, Chris" <Chris.Br...@sopranewellandbudge.com>
Subject AXIS Serialization / Deserialization problem with namespace prefixes
Date Wed, 10 May 2006 14:49:53 GMT
Hi, 
 
  I am using the code below to serialize / deserialize AXIS beans back
and forth to XML.
  However, I have recently came across a situation where say...
 
  Original
  <n:test xmlns:n="http:/blah">
    <bob>1</bob>
    <jim>2</jim>
  </n:test>
 
   Turns in to    
  <n:test xmlns:n="http:/blah">
    <n:bob>1</n:bob>
    <n:jim>2</n:jim>
  </n:test>
 
  Once serialization / deserialization has occured.
 
  Does anyone know of a way to prevent this happening as it causing a
lot of problems when attempting to use
  XPath on the resulting XML document.
 
Many thanks in advance
Chris
 
=====================================
 
 
 
Andy,

This should make your boss happy:

public static Document serializeFromBinding(Object object, QName qname)
            throws ApplicationException {

        MessageContext msgContext = new MessageContext(new
AxisServer());
        msgContext.setEncodingStyle(null);

        TypeMappingRegistry tmr = new TypeMappingRegistryImpl();
        msgContext.setTypeMappingRegistry(tmr);

        StringWriter writer = new StringWriter(); //temp
        SerializationContext ser = new SerializationContext(writer,
msgContext);
        ser.setPretty(true);
        ser.setSendDecl(false);
        ser.setDoMultiRefs(false);

        try {
            ser.serialize(qname, new AttributesImpl(), object, null,
Boolean.FALSE, Boolean.FALSE);
            writer.flush();
            return XMLUtils.newDocument(new InputSource(new
StringReader(writer.toString())));
        }
        catch(ParserConfigurationException e) {
            throw new ApplicationException(e.getMessage(), e);
        }
        catch(SAXException e) {
            throw new DocumentStructureException(e.getMessage(), e);
        }
        catch(IOException e) {
            throw new ApplicationException(e.getMessage(), e);
        }
    }

Yves

On Fri, 2005-11-11 at 18:10 -0500, Andy Foster wrote:
> Hi all,
> 
> I'm at my last chance now, so if someone can help that would be great
else
> I'm going to have to hand code XML output.
> 
> If you use WSDL2JAVA to generate stubs and call them you get a java
response
> object back that represents the XML response
> 
> I need to get that response back into XML not the stub java
representation.
> 
> I know axis can re serialise for me I just do not know how to invoke
it
> 
> Please help as I have been searching for two days now and my boss is
giving
> me the weekend and then we have to find another way to hand crank it
which
> would be a very poor solution
> 
> Andy

 
Chris Brown
System Builder
Sopra Newell & Budge 


Tel	 +44 (0)131 332 3311 	 	 Fax	 +44 (0)131 332 5938

 	
 	
Sopra Newell & Budge, Queensway House, 1 Queensferry Terrace, Edinburgh,
EH4 3ER 	
www.sopranewellandbudge.com <http://www.sopranewellandbudge.com/>  	
 

_____________________________________________________________________________________________________

Sopra Newell & Budge is the trading name of: Newell & Budge Limited (Registered in
Scotland No. 94545 with Registered Offices at: 1 Queensferry Terrace, Edinburgh, EH4 3ER,
VAT No. 774 7553 86), Newell & Budge Security Limited (Registered in Northern Ireland
No. 39008, with Registered Offices at: 199 Airport Road West, Belfast, BT3 9ED, VAT No. 774
7553 86) and Sopra Group Limited (Registered in England, No. 1588948 with Registered Offices
at: 17 St Helen's Place, London, EC3A 6DG, VAT No. 366 9784 84).

IMPORTANT NOTICE: This message is intended for the addressee only. The content may be confidential,
legally privileged and protected by law. Unauthorised use, copying or disclosure of any of
it may be unlawful. If you are not the intended recipient please notify the sender and remove
it from your system. Internet e-mails are not necessarily secure. Although we have taken steps
to ensure this e-mail and attachments are free from any virus, we advise that in keeping with
good computing practice you should ensure they are actually virus free. The right to monitor
e-mail communications through our network is reserved by Sopra Newell & Budge.
_____________________________________________________________________________________________________
Mime
View raw message