public class XMLCoder extends Coder
Important: If you use XMLCoder to encode Values objects, then you MUST use XMLCoder. to decode it. Although webMethods may change the XML format produced by this class in the future, it will always remain backwardly compatible. If you modify the XML outside of XMLCoder methods, you might not be able to decode that XML in a future release.
XMLCoder can encode Values objects that contain any of the following Object types.
Primary Types
ValuesCodable | StringCodable | IDataCodable (when decoded creates a Values object) |
Values | Codable | Vector |
Number | String | IData (when decoded creates a Values object) |
Array Types
String[] | IData[]> (when decoded creates a Values[] object) | IDataCodable[] (when decoded creates a Values[] object) |
Object[] | String[][] | Vector |
Objects other than those listed above are not supported, and XMLCoder will not encode or decode them. If an unsupported object is contained in a Values object that you are encoding, XMLCoder will post a warning message to the debug log.
Note: We recommend that you use the UTF8 character set to encode and decode your XML documents to ensure that your solution is compatible with international character sets.
XMLCoderWrapper
,
IDataXMLCoder
,
Codable
,
IDataCodable
,
StringCodable
,
ValuesCodable
Constructor and Description |
---|
XMLCoder()
Constructs an XMLCoder object that defaults to file.encoding for encoding and decoding XML
|
XMLCoder(boolean utf8)
Constructs an XMLCoder object that uses the UTF8 character set to encode to and decode XML documents.
|
Modifier and Type | Method and Description |
---|---|
Values |
decode(java.io.InputStream is)
Decodes the XML in the specified InputStream to a Values object.
|
void |
encode(java.io.OutputStream os,
Values data)
Encodes the specified Values object as an XML document and writes that document to an OutputStream.
|
java.lang.String |
getContentType()
Returns a String object indicating the current content type.
|
void |
setContentType(java.lang.String ctype)
Sets the content type.
|
void |
setIgnoreInvalid(boolean ignore)
Sets a boolean flag that specifies whether this XMLCoder ignores unsupported object types in the data that it encodes or decodes.
|
void |
setRootTag(java.lang.String tag)
Specifies the root tag for XML.
|
void |
setUseOIDs(boolean use)
Specifies whether Object Identifiers (OIDs) are assigned to object values.
|
void |
setUseUTF8(boolean use)
Sets a boolean flag that specifies whether the UTF8 character set is used to encode and decode XML.
|
void |
setUseXMLHeader(boolean use)
Sets a boolean flag that specifies whether or not an XML header (for example, <?xml version="1.0" encoding "UTF-8" >) is included in the XML document.
|
decodeFromBytes, encodeToBytes, readFromFile, readFully, writeToFile
public XMLCoder()
public XMLCoder(boolean utf8)
utf8
- A boolean specifying whether this XMLCoder will use UTF8 character set when encoding to or decoding from XML.
Set utf8 to
|
To
|
true | Use UTF8 character sets |
false | Use file.encoding (default) |
public Values decode(java.io.InputStream is) throws java.io.IOException, InvalidDatatypeException
decode
in class Coder
is
- An InputStream that originates from a specific XML source.java.io.IOException
- If an error occurs while reading InputStream.InvalidDatatypeException
- If the XML in InputStream cannot be decoded or it contains an unsupported object type and setIgnoreInvalid is false.setIgnoreInvalid(boolean)
,
setUseUTF8(boolean)
,
encode(java.io.OutputStream, com.wm.util.Values)
public void encode(java.io.OutputStream os, Values data) throws java.io.IOException, InvalidDatatypeException
encode
in class Coder
os
- The OutputStream into which you want the XML-encoded Values object written.data
- The Values object that you want to encode.java.io.IOException
- If error occurs while writing to the OutputStream.InvalidDataTypeException
- If the Values object contains an unsupported object type and setIgnoreInvalid is false.InvalidDatatypeException
- If the data in the Values object cannot be encoded (i.e.,
the Values object contains an object type that is not supported by the specific
implementation of encode that you are using.)setIgnoreInvalid(boolean)
,
setUseUTF8(boolean)
,
decode(java.io.InputStream)
public java.lang.String getContentType()
getContentType
in class Coder
setContentType(java.lang.String)
public void setContentType(java.lang.String ctype)
Note: If you want to use the standard webMethods ContentHandler, then do not use this method to override the default content type with a custom one.
ctype
- A String specifying the content type for this XMLCoder.getContentType()
public void setIgnoreInvalid(boolean ignore)
ignore
- A boolean specifying whether unsupported objects are ignored.
Set ignore to
|
To
|
true | Ignore unsupported objects types when encountered (default). |
false | Throw an InvalidDataTypeException when an unsupported object type is encountered. |
public void setRootTag(java.lang.String tag)
Note: If you need to set the root tag, set it before using the writeToFile or readFromFile methods.
tag
- A String specifying the root tag.public void setUseOIDs(boolean use)
use
- A boolean specifying whether to assign Object Identifiers (OID) to each object value.
Set use to
|
To
|
true | Assign OIDs to object values. |
false | Omit OIDs from object values. |
public void setUseUTF8(boolean use)
Note: We recommend that you use the UTF8 character set to encode and decode your XML documents to ensure that your solution is compatible with international character sets.
use
- A boolean specifying whether this XMLCoder will use the UTF8 character set to encode and decode XML.
Set use to
|
To
|
true | Use UTF8 character sets. When set to true, XMLCoder includes the encoding declaration encoding='UTF8' in the XML it generates. |
false | Use file.encoding. When set to false, XMLCoder omits the encoding declaration from the XML it generates. (default) |
public void setUseXMLHeader(boolean use)
use
- A boolean specifying whether this XMLCoder will include an XML header when it encodes a Values object as XML.
Set use to
|
To
|
true | Include the XML header. (default) |
false | Omit the XML header. |