public class XmlData
extends java.lang.Object
The XmlData feature encodes the XML Infoset as IData structures using a format similar to, but more advanced than, the legacy format of prior implementations. The structure of IData itself is completely unaffected by this feature. Rather, this feature adds a layer of formalism to the way in which XML infosets are represented using IData. This new format is independent of the legacy implementation; the legacy implementation, services, and applications that use the legacy format will continue to function without change. The new format is exploited using a separate set of public services and helper classes. The two formats cannot be intermixed. The XmlData content should not reference legacy content, and legacy XML content should not reference XmlData content. However, either or both types of content can be referenced from an IData that does not represent XML encoded data (for example the Integration Server pipeline).
The encoding format also conforms to the format of the new XML document types, though it is possible to use XmlData without using XML document types. The new XML document types more fully represent the capabilities of XML and XML Schema.
This new format is created from XML and converted back to XML using new services in the pub.xmldata folder in the WmPublic package. The new format may also be created and updated using the facilities of this XmlData helper class and the XmlDataCursor class. The new content is defined using hierarchies of Document Types. This makes it possible for Flow Map manipulate the new format in ways very similar to the legacy format.
Like the legacy approach, XMlData uses IData objects to represent complex content as key/value pairs. Likewise, it uses Strings to represents simple content. Repeating elements (schema minOCcurs > 1) are represented as arrays. However, the XmlData format allows no other object type, not even Java null. Empty simple content must be represented as empty Strings and empty complex content must be represented as empty IData objects.
In a more obvious departure from the legacy format, the XmlData feature encodes QNames as ncname#url rather than
prefix:ncname. This eliminates the need for and complexity of
a secondary definition of the namespace elsewhere such as in a document type or in an instance nsdecls
map.
Using a simple example, the XML content:
<inv:address xmlns:inv="www.invoice.com">555 Mockingbird Lane</inv:address>is represented in the legacy format using IData as key/value pair:
"inv:address" :: "555 Mockingbird Lane"with the prefix "inv" being defined externally. While in the new XmlData format, it is represented as an IData key/value pair:
"address#www.invoice.com" :: "555 Mockingbird Lane"
When creating XML document types from schemas, model groups (sequence, choice, and all) are represented using a field named *group
with a content type of Document. The Document contains the child content definition of the group.
When complex content has attributes, the attributes are encoded under a separate Document containing the attributes. This separate IData value
has a key named *attributes
. If simple content is present with attributes, it is encoded using the key *simple
.
If a schema contains an "any" element wildcard, that particle is represented as a field with name *any
and a content of Document.
The Document content is a very specialized any object format, which is described later.
If a schema contains substitution groups, the head of a substitution group is encoded as field with name *substitution-
name with a very
specialized IData content, which is described later.
The members of model groups are further qualified by a leading prefix of the form {1}, {2}, ... etc. This prefix uniquely identifies particles in
a group since more than one particle with the same name can appear throughout a content model. This qualification is necessary because more than
one particle with the same name can appear throughout a content model. Such qualification * applies to ordinary elements as well as particles
with reserved names: *group, *any, and particle that starts with *substitution-.
This qualification is present even when the names are not repeated.
This qualification is in addition to element repetition. For example, an element named "student" might have a maxOccurs property of 5 in one part of a content model
and a maxOccurs property of 1 at some later point in the model. Thus, the first occurrence {1}student
is defined as an array while the second
occurrence {2}student
is a scalar. In similar fashion, a content model might contain two choice groups. The first choice group is defined by a field with
name {1}*group
while the second choice group is defined by a field named {2}*group
.
These examples illustrate the encoding. For clarity, unqualified names are used, though the same layout is used for qualified names.
Simple String content such as:
<name>kilroy</name>is encoded as a single IData key/value pair with the value being a simple String:
IData "{1}name" :: "kilroy"Note that the
name
field has been prefixed with {1}
to denote the first occurrence of the element in the content.
More complex content such as
<people xmlns:family> <brother>Sam</brother> <sister>Karen</sister> <brother>Bill</brother> </people>is encoded in a similar way with multiple kye/value pairs:
"{1}people#family" :: IData "{1}brother#family" :: "Sam" "{1}sister#family" :: "Karen" "{2}brother#family" :: "Bill"Note that field names such as
{1}brother#family
include the XML namespace.
Also note that there are distinct occurrences of the * brother#family
element each with a unique prefix.
However, if content contains adjacent repeating elements, the content is represented as an array.
<people xmlns:family> <brother>Sam</brother> <brother>Bill</brother> <sister>Karen</sister> </people>is encoded in a somewhat similar way, but uses a String[] for the repeated value
"{1}people#family" :: IData "{1}brother#family" :: String[] "Sam" "Bill" "{1}sister#family" :: "Karen"Content with attributes such as:
<item size="medium" color="blue"> <supplier>ABC Inc.</supplier> <distributor> XYZ Inc.</distributor> </item>is encoded as two separate sub-documents named *attributes and *group
"item" :: IData "*attributes" :: IData "size" :: "medium" "color" :: "blue" "{1}*group" :: IData "{1}supplier" :: "ABC Inc." "{1}distributor" :: "XYZ Inc."When an element has attributes but only simple content, such as
<item size="medium" color="blue">shoe</item>the simple content is encoded as a *simple key/value pair rather than a *group sub-document
"item :: IData "*attributes" :: IData "size" :: "medium" "*simple" :: "shoe"
In the preceding examples, the *group item was present only because attributes were also present. Otherwise, the *group items are not typically needed when only child elements are present. However, if an element has maxOccurs > 1 and its top level model group also has maxOccurs > 1, it is necessary that the *group item be present because both the element and the group have repeating values stored as arrays. For example, given this XML document,
<emplyees> <name>Sam</name> <address>Mars</address> <name>Mary</name> <address>Venus</address> </employees> <employees> <name>George</name> <address>Pluto</address> <name>Sally</name> <address>Saturn</address> </employees>If employees is defined as a particle with maxOccurs > 1 and its content model is defined as multiple repetitions of name and address, then the IData representation of the XML is:
"employees" :: IData[] [0] IData "*group" :: IData[] [0] IData "name" :: "Sam" "address" :: "Mars" [1] IData "name" :: "Mary" "address" :: "Venus" [1] IData "*group" :: IData[] [0] IData "name" :: "George" "address" :: "Pluto" [1] IData "name" :: "Sally" "address" :: "Saturn"It is possible to use XmlData without following the document type model. When no XML document types are in use, it is not possible to manipulate XmlData from Flow. It is also not possible to validate the content. When XML document types are not used, there are no wildcards, substitution heads, or model groups. Therefore, it is not necessary, or even desirable to create wildcard, group, or substitution content when not using XML documnet types. In addition, the public services always represent repeating content as Object[] when XML document types are not in use. This greatly simplifies the use of XmlData when XML document types are not used.
Constructor and Description |
---|
XmlData() |
Modifier and Type | Method and Description |
---|---|
static IData |
createAnyObject(XmlDataElementTag tag,
java.lang.Object content)
Creates an IData object in the form of a *any value.
|
static IData |
createAttributes(java.lang.Object... pairs)
Creates the attribute content for a complex type.
|
static IData |
createComplexValue()
Creates new empty complex value.
|
static IData |
createComplexValue(IData attributes,
java.lang.Object content)
Creates a new populated complex value.
|
static IData |
createGroupValue(java.lang.Object... pairs)
Creates new group content.
|
static IData |
createSubstitutionObject(XmlDataElementTag tag,
java.lang.Object content)
Creates an IData object in the form of *substitution content.
|
static boolean |
equalTo(java.lang.Object objA,
java.lang.Object objB)
Tests equality of two XmlData formatted objects.
|
static java.lang.Object |
getAnyValue(IData anyContent)
Returns the content of a *any formatted IData object
|
static XmlDataElementTag |
getAnyValueKey(IData anyContent)
Returns the XmlDataElementTag from the *any formatted IData object
|
static java.lang.Object |
getContent(java.lang.Object parent)
Finds the content of an Object that was retrieved using XmlDataCursor.getValue().
|
static java.lang.String |
getInstanceProp(IData data,
XmlDataElementTag tag,
java.lang.String prop,
int... index)
Retrieves an xsi property on an element
|
static IData |
getNamespacePrefixes(IData data,
XmlDataElementTag tag,
int... index)
Gets all prefix/URI pairs for a an element
|
static java.lang.String |
getNamespacePrefixValue(IData data,
XmlDataElementTag tag,
java.lang.String prefix,
int... index)
Gets the namespace URI for the specified prefix
|
static java.lang.Object |
getSubstitutionValue(IData substitutionContent)
Returns the value of the substituted element in the *substitution formatted content
|
static XmlDataElementTag |
getSubstitutionValueKey(IData substitutionContent)
Returns the XmlDataTag of the substitution content.
|
static XmlDataCursor |
getXmlDataCursor(IData root)
Returns an XmlDataCursor on the specified IData object.
|
static void |
setAnyValue(IData anyContent,
java.lang.Object value)
Sets the value in the *any content
|
static void |
setAnyValueKey(IData anyContent,
XmlDataElementTag name)
Sets the XmlDataElementTag in the specified *any content
|
static void |
setInstanceProp(IData data,
XmlDataElementTag tag,
int index,
java.lang.String xsitag,
java.lang.String xsivalue)
Sets the xsi prop declaration for a given XmlData element with repeating values.
|
static void |
setInstanceProp(IData data,
XmlDataElementTag tag,
java.lang.String xsitag,
java.lang.String xsivalue)
Sets the xsi prop declaration for a given XmlData element with a non-repeating value.
|
static void |
setNamespacePrefix(IData data,
XmlDataElementTag tag,
int index,
java.lang.String prefix,
java.lang.String namespace)
Sets the prefix/namespace declaration for a given XmlData element with a repeating values.
|
static void |
setNamespacePrefix(IData data,
XmlDataElementTag tag,
java.lang.String prefix,
java.lang.String namespace)
Sets the prefix/namespace declaration for a given XmlData element with a non-repeating value.
|
static void |
setSubstitutionValue(IData substitutionContent,
java.lang.Object value)
Sets the value of the substituted element in *substitution content
|
static void |
setSubstitutionValueKey(IData substitutionContent,
XmlDataElementTag tag)
Sets the XmlDataElementTag for the substituted element in *substitution content
|
public static IData createAnyObject(XmlDataElementTag tag, java.lang.Object content)
tag
- the XMlDataTag for the contentcontent
- the content valuepublic static IData createAttributes(java.lang.Object... pairs)
pairs
- pairs of alternating XmlDataAttributeTags and Strings.public static IData createComplexValue()
XmlDatCursor#setContent
,
XmlDatCursor#setAttributes
public static IData createComplexValue(IData attributes, java.lang.Object content)
attributes
- - the attribute values, typically constructed by a call to XmlData.createAttributescontent
- - the complex value content (either a String for simple, or an IData for group)XMLDataException.UnsupportedType
- if attributes content is not IData or if the content is not a String or IDatacreateAttributes(java.lang.Object...)
,
XmlDatCursor#setContent
,
XmlDatCursor#setAttributes
public static IData createGroupValue(java.lang.Object... pairs)
pairs
- possibly empty Object[] where even members are instances of XmlDataContentTag subclasses and odd members are content
objects suitable for their corresponding tag that immediately precedes them.XmlDataException.TagAndContentConflict
- if an odd number of arguments is specifiedXmlDataException.TagAndContentConflict
- if one of even-number arguments is an XmlDataTagpublic static IData createSubstitutionObject(XmlDataElementTag tag, java.lang.Object content)
tag
- the XmlDataElementTag of the substituted elementcontent
- the contentpublic static boolean equalTo(java.lang.Object objA, java.lang.Object objB)
objA
- the first ObjectobjB
- the second Objectpublic static java.lang.Object getContent(java.lang.Object parent)
parent
- the parent Objectpublic static XmlDataElementTag getAnyValueKey(IData anyContent)
anyContent
- the IData object in the *any formatpublic static java.lang.Object getAnyValue(IData anyContent)
anyContent
- the IData object in the *any formatpublic static java.lang.String getInstanceProp(IData data, XmlDataElementTag tag, java.lang.String prop, int... index)
data
- the parent IDatatag
- the XMlDataElementTag to be queriedprop
- the property queried, for example: type, nilindex
- the optional offset into repeating valuespublic static java.lang.String getNamespacePrefixValue(IData data, XmlDataElementTag tag, java.lang.String prefix, int... index)
data
- the parent IDatatag
- the XmlDataElementTag to be queriedprefix
- the prefix queriedindex
- the optional offset index if repeating values are presentpublic static IData getNamespacePrefixes(IData data, XmlDataElementTag tag, int... index)
data
- the parent IData objecttag
- the XmlDataElementTag for which the pairs are retrievedindex
- option offset in array if repeating values are presentpublic static XmlDataElementTag getSubstitutionValueKey(IData substitutionContent)
substitutionContent
- content that is in substitution group format (must be an IData)public static java.lang.Object getSubstitutionValue(IData substitutionContent)
substitutionContent
- the *substitution formatted contentpublic static XmlDataCursor getXmlDataCursor(IData root)
root
- the IData object for which an XmlDatCursor is createdpublic static void setAnyValueKey(IData anyContent, XmlDataElementTag name)
anyContent
- the value of the element wildcardname
- the XmlDataElementTag naming the wildcard elementXmlDataException.UnsupportedType
- if content is nullpublic static void setAnyValue(IData anyContent, java.lang.Object value)
anyContent
- the IData object that is formatted as *any contentvalue
- the value to set in the *any content formatXmlDataException.UnsupportedType
- if content is nullpublic static void setInstanceProp(IData data, XmlDataElementTag tag, java.lang.String xsitag, java.lang.String xsivalue)
data
- the IData parent of the elementtag
- the tag of the elementxsitag
- the xsi tag namexsivalue
- the xsi tag valuepublic static void setInstanceProp(IData data, XmlDataElementTag tag, int index, java.lang.String xsitag, java.lang.String xsivalue)
data
- the IData parent of the elementtag
- the tag of the elementindex
- the index of the repeated value to which the xsi declaration is appliedxsitag
- the xsi tag namexsivalue
- the xsi tag valuepublic static void setNamespacePrefix(IData data, XmlDataElementTag tag, java.lang.String prefix, java.lang.String namespace)
data
- the IData parent of the elementtag
- the tag of the elementprefix
- the prefix for the declarationnamespace
- the namespace URI for the declarationpublic static void setNamespacePrefix(IData data, XmlDataElementTag tag, int index, java.lang.String prefix, java.lang.String namespace)
data
- the IData parent of the elementtag
- the tag of the elementindex
- the index of the repeated value to which the namespace declaration is appiedprefix
- the prefix for the declarationnamespace
- the namespace URI for the declarationpublic static void setSubstitutionValueKey(IData substitutionContent, XmlDataElementTag tag)
substitutionContent
- the *substitution formatted IData objecttag
- the XmlDataELement tag of the substituted elementXmlDataException.UnsupportedType
- if null content is specifiedpublic static void setSubstitutionValue(IData substitutionContent, java.lang.Object value)
substitutionContent
- the IData content of the substitution groupvalue
- the value assigned to the substitution grupXmlDataException.UnsupportedType
- if a null content is specified