webMethods Integration Cloud and Cloud Deployment Documentation 5.6.0 | webMethods Integration Cloud | Integrations, Built-In Services, REST APIs, SOAP APIs, Doc Types, and Recipes | Built-In Services | XML | documentToXMLBytes
 
documentToXMLBytes
Converts a document to xml content bytes, as a byte array object. This service will recurse through a given document and build an XML representation from the elements within it. Key names are turned into XML elements, and the key values are turned into the contents of those elements.
This service will convert the following document:
To XML document bytes (byte array object), whose content looks like:
<?xml version="1.0" ?>
<tns:AcctInfo>
xmlns:tns="http://localhost/DerivedAddress/schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>Midwest Extreme Sports</name>
<rep>Laura M. Sanchez</rep>
<acctNum type=platinum>G97041A</acctNum>
<phoneNum cc=011>216-741-7566</phoneNum>
<address country=USA><street1>10211 Brook Road</street1>
<city>Cleveland</city>
<state>OH</state>
<postalCode>22130</postalCode>
</address>
<address country=USA xsi:type="tns:DerivedAddress">
<street1>10211 Brook Road</street1>
<city>Cleveland</city>
<state>OH</state><postalCode>22130</postalCode>
<landMark>Besides Ohio River-Bank Square</landMark>
<telNo>001222555</telNo>
</address>
<serialNum>19970523A</serialNum>
<serialNum>20001106G</serialNum>
<serialNum>20010404K</serialNum>
</tns:AcctInfo>
Input Parameters
document
Document. Document that is to be converted to XML. Note that if you want to produce a valid XML document (one with a single root node), document must contain only one top-level document that is, a single document. The name of that document will serve as the name of the XML document's root element. If you need to produce an XML fragment, for example, a loose collection of elements that are not encompassed within a single root element, then document can contain multiple top level elements.
nsDecls [ ]
Document. Optional. Namespaces associated with any namespace prefixes that are used in the key names in document. Each entry in nsDecls represents a namespace prefix/URI pair, where a key name represents a prefix and the value of the key specifies the namespace URI. For example, to define the URIs associated with two prefixes called GSX and TxMon, you would set nsDecls as follows:
For each prefix specified in nsDecls, this service generates an xmlns attribute and inserts it into the top-most element of the resulting XML String. For example, if nsDecls had the two keys shown above, this service would insert the following attribute into the root element of the XML String:
xmlns:gsx="http://www.gsx.com"
xmlns:TxMon="http:www.acrtrak/txMonitor"
Alternatively, you can declare a namespace by including an @xmlns key in document. If you were not using the @ character to designate attributes, use the correct attribute prefix in your code.
Parameters for nsDecls [ ] are:
prefix: Key name.
uri: Key value.
addHeader
String. Optional.
Flag specifying whether the header element <?xml version="1.0"?> is to be included in the resulting XML String.
Set to:
true to include the header. This is the default.
false to omit the header. Omit the header to generate an XML fragment or to insert a custom header.
Output Parameters
xmlBytes
Object. XML content bytes (byte array) produced from document.
Usage Notes
If you are building a Document that will be converted to an XML String, keep the following points in mind:
If you want to generate a simple element that contains only a character value, represent it with a String element in the document as shown below:
If you want to generate an element that contains children, represent with a document in the document as shown below:
If you want to generate a simple element that contains a character value and one or more attributes, you must represent it as a document that has one key for each attribute and a key named *body that contains the element's value.
For example, if you want to produce the following element:
<phoneNum cc=011>216-741-7566</phoneNum>, you would include the following in document:
To include namespaces, ensure that you do the following:
Include the appropriate namespace prefix in the key names in document. For example, to produce an element called acctNum that belongs to a namespace that is represented by the "GSX" prefix, you would include a key named GSX:acctNum in document.
Define the URIs for the prefixes that appear in document. You can do this through nsDecls or by including an @xmlns key in the element where you want the xmlns attribute to be inserted.

Copyright © 2014- 2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.