I have added the following FAQ entry now.

Apache XML-RPC is sending strings as <value>SomeString</value>.
Whereas I would expect <value><string>SomeString</string></value>.

    Both formats are valid. XML-RPC compliant software (as Apache
XML-RPC is) must be able to understand both. Of course, you can only
produce one. Unfortunately there are a lot of processors out there,
which understand just one. Which is the reason, why this FAQ entry
exists.

    Fortunately, it is not overly difficult to change the format, that
Apache XML-RPC produces. First of all, create a custom type factory:

        package mypackage;

        import org.apache.xmlrpc.common.TypeFactoryImpl;
        import org.apache.xmlrpc.common.XmlRpcController;
        import org.apache.xmlrpc.common.XmlRpcStreamConfig;
        import org.xml.sax.ContentHandler;
        import org.xml.sax.SAXException;

        public class MyTypeFactory extends TypeFactoryImpl {
            private static final TypeSerializer myStringSerializer =
new StringSerializer(){
                public void write(ContentHandler pHandler, Object
pObject) throws SAXException {
                    write(pHandler, STRING_TAG, pObject.toString());
                }
            };

            public MyTypeFactory(XmlRpcController pController) {
                super(pController);
            }

            public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig,
                    Object pObject) throws SAXException {
                if (pObject instanceof String) {
                    return myStringSerializer;
                }
                return super.getSerializer(pConfig, pObject);
            }
       }


    Then you'e got to install that custom type factory. This works as
described in the section on "Custom Data Types".

Reply via email to