Package com.topologi.diffx.xml
Class XMLSerializer
java.lang.Object
com.topologi.diffx.xml.XMLSerializer
This class provides methods to serialize objects to XML.
There is no mechanism to prevent infinite loops if some objects (lists,...) reference themselves.
The underlying XML document is generated using an XML string buffer.
- Version:
- 7 March 2005
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DateFormatDate formatter.private final XMLWriterUsed to store the xml document of this class. -
Constructor Summary
ConstructorsConstructorDescriptionXMLSerializer(XMLWriter xml) Creates a new XML serializer using the specified XML writer. -
Method Summary
Modifier and TypeMethodDescriptiongetXML()Returns the underlying XML document.voidSerialises the given object using the given name as element name.voidSerialises the given Collection to xml.voidserializeHashtable(Hashtable<?, ?> h) Serialise the givenHashtableto xml.voidSerialises the given object to xml by using the public methodsgetXXX().
-
Field Details
-
DF
Date formatter. -
xml
Used to store the xml document of this class.Classes extending this class should use their constructors to set the size of the
XMLStringBuffer.
-
-
Constructor Details
-
XMLSerializer
Creates a new XML serializer using the specified XML writer.- Parameters:
xml- The XML string buffer to be used
-
-
Method Details
-
getXML
Returns the underlying XML document.- Returns:
- the xml stringbuffer
-
serialize
Serialises the given object using the given name as element name.This implementation is recursive. It calls itself for fields which are not of primitive type.
- Parameters:
o- Object to be serialised as xmlname- Name of object- Throws:
IOException- Should an I/O error occur.
-
serializeCollection
Serialises the given Collection to xml.Iterates over every object and call the
serialize(java.lang.Object, java.lang.String)method.- Parameters:
c- The Collection to be serialised to XML- Throws:
IOException- Should an I/O error occur.
-
serializeHashtable
Serialise the givenHashtableto xml.This methods only works if the
HashtablecontainsStringobjects.- Parameters:
h- The hashtable to be serialized to XML- Throws:
IOException- Should an I/O error occur.
-
serializeObject
Serialises the given object to xml by using the public methodsgetXXX().This method calls every
getXXX()method from the object to get the returned object and then calls theserialize(Object, String)method with the returned object and the name xxx in lower case.- Parameters:
o- The object to be serialised as XML- Throws:
IOException- Should an I/O error occur.
-