Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals August 1, 2010

Appendix B - XML Fundamentals

XML is the acronym for eXtensible Markup Language. XML was derived from SGML – starting life around 1996. XML‟s primary purpose has become to share structured data across organizations and technologies. As such it forms the foundation for almost anything we do in the SOA Suite. A solid understanding of XML and some of its associates - XML Schema Definition, XPath, XSLT - is required to make the most (and sometimes even the smallest bit) of the SOA Suite 11g. This chapter gives some introduction and background on XML and friends. Note however that is merely a very superficial overview and that if these concepts are entirely new to you, you will probably have to consult other resources to crank up your understanding of XML, namespaces, XPath, XSD and XSLT. Also note that this appendix continues where the discussion in chapter 4 stops. For good measure we also throw in some examples of how XML cs. can be used and manipulated in Java and PL/SQL, our favorite programming languages. We conclude by making some inroads into the domain of WebServices, the other pillar of the SOA Suite and itself resting on the XML and XSD underpinnings introduced early on in this appendix.

Introducing XML
Clearly XML is an essential ingredient of Service Oriented Architecture. Service definitions are expressed via XML documents, the data structure of messages is defined through XML documents, configuration for the run time infrastructure is by and large in XML, the contents of messages sent between Services and Service Consumers is XML based and the SOAP envelop that wraps the message itself is also – you guessed it – an XML document. In order to delve into doing SOA, there are a few things that you should know about XML. For now


Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals

August 1, 2010

we will assume you have dealt with XML in the past. For a basic introduction into XML as well as a list of other resources with in depth information on XML, see Appendix 2. Much of the attraction of XML lies in the fact that in all major application development technologies, tools and platforms, facilities are available for performing the most frequently needed operations on XML. Whether you develop in JavaScript, PHP, Java, C# or PL/SQL, for the JEE, .NET or Oracle platform, you will have native language facilities that help you process XML documents. These operations performed on XML documents are:  Parsing – read the XML and turn it into a native data object for the programming language at hand  Data Binding – go one step beyond parsing and make the data from the XML document available as a custom, strongly typed programming language data structure, aka domain model  Validating – verifying the validity of the XML document against rules specified in a schema such as XSD or Schematron  Querying – retrieving specific information from the XML document by applying search questions  Transforming – convert the XML document based on a particular schema into an XML document based on a different schema by applying a transformation template or stylesheet While some of the operations listed above are handled transparently for us by the tools we will be using for building the SOA, others will be discussed in more detail later in this chapter and also make frequent appearances throughout the book. Especially the use of XML Schema Definitions for describing the rules against which XML documents should be validated, the use of XPath for performing queries to retrieve specific information from XML documents and the application of XSLT stylesheets for transforming XML documents will be fairly familiar by the time you are done with this book.


Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals August 1, 2010

XML is the acronym for eXtensible Markup Language. XML was derived from SGML – starting life around 1996. XML‟s primary purpose has become to share structured data across organizations and technologies. XML is intended to be readable by humans as well as software. XML documents are expressed in plain text, with many different encodings supported. The most important encoding is Unicode (UTF-8 or UTF-16), while ISO-8859 is also frequently used. An XML document will typically look like an over-structured text-document, that contains both data and meta-data. XML documents are often called verbose – as they tend to contain a lot of text compared to the actual data content. The extensibility of XML lies in the fact that anyone can use the basic XML lexical grammar rules and create custom markup languages by defining new elements element hierarchies. A lot of specific application languages have been defined based on XML. These include XHTML, RSS, Scalable Vector Graphics (SVG) and the Open Document Format(ODF) and its counterpart OfficeOpen XML (OOXML).

XML Documents
An XML document consists of tagged elements organized in a tree-like structure. An XML document contains various types of nodes:      document node (the entire document) element node text node (the literal values contained in element nodes) attribute node comment node

These nodes can be accessed in various ways in XPath Queries and XSLT Transformations, as we have seen through this book. An XML document usually starts with the XML declaration, a single line stating that it is indeed an XML document, based on version 1.0 of the XML specification. This line also


Comments can be inserted in an XML document using the <!-. <?xml version="1. Elements need to be correctly nested: a child element starts and ends within its parent.0" encoding="UTF-8" ?> The real content of the XML document is in a tree structure. The name of an element is case sensitive. An element tag starts with < (the less-than character) and ends with > (the greater-than character). 2010 specifies the encoding used for the document – frequently this will be UTF-8. Note how an element consists of a start-tag and an end-tag with possibly attributes. a literal data value and child elements in between. That means that <Patient> is not the same element type as <patient>. Note: forward slash is the more common word for virgule.XML Fundamentals August 1. rooted in a single element. Solomon</treatingPhysician> <prescription/> <charge>243. although ISO8859-1 is fairly common as well. The end-tag has a virgule immediately following the < character. It contains two child elements: personal and doctorVisits.start and --> end enclosure. In this example. patient is the root element.32</charge> </doctorVisit> </doctorVisits> 8-4 .0" encoding="UTF-8" ?> <patient> <personal> <firstName>Mildred</firstName> <lastName>Huston</lastName> </personal> <!-.list of (at most) the three most recent visits --> <doctorVisits> <doctorVisit dateOfVisit="2008-12-31" > <treatingPhysician>Dr. <?xml version="1.Oracle 11g SOA Suite Handbook: Appendix B .

it seems largely a matter of personal preference.XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B . are case sensitive. Tools are typically capable of handling both child elements and attributes. Such empty elements can be abbreviated using a single tag that includes the virgule: <prescription/> Attributes are key-value pairs. At the end of the day. Two clear distinctions between attributes and child elements is that child elements can have nested child elements of their own (and attributes for that matter) and can have multiple occurrences. 15-5 . like attributeName1="value" attributeName2="value" Attribute names. 2010 </patient> The prescription element is empty: it does not have child elements nor does it have attributes. separated from each other by whitespace characters. with the value between quotes. There is some debate about whether to use attributes in XML elements – such as the dateOfVisit attribute in the doctorVisit element – or stick to child elements to associate data values with elements. Attributes in contrast are unique within their element and contain only simple values. like element names.

XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B . Used for & 8-6 . 2010 The tree structure of the Patient XML document Special Characters Characters such as < and > are part of the infrastructure of an XML document. XML defines a number of special characters that you can use in those situations: Entity &amp. there may be occasions when you want to use these characters in the actual content. However.

it can become quite a nuisance. 15-7 .introducing Namespaces One of the interesting questions we frequently should ask when we encounter an element in an XML document is: what element definition is this element based on? What exactly is meant with this element? Patient can refer to a person needing doctor‟s attention but could also describe a characteristic. XML allows us to include CDATA sections. with frequent occurrences for example in longer text fragment. >. they are plain text. just content.Oracle 11g SOA Suite Handbook: Appendix B . These signify exact Unicode codepoints in either decimal (nnnn) or hexadecimal (hhhh) format. & and “ in abundance: to tools processing the document. &gt. or &#hhhh. Any text inside a CDATA section is ignored by XML parsers and contributes no structure to the document. it is okay to have to resort to these somewhat cumbersome entities. Burke]]></treatingPhysician> One other special type of reference you may encounter in XML documents is &#nnnn.. A table element could signify an HTML layout structure or a piece of furniture. &apos. 2010 &lt. A CDATA section is used in a text node like this: <treatingPhysician><![CDATA[Dr. < > “ „ For the occasional appearance of a lone < or & character. The true identity of XML elements . And incorporating data from XML unaware sources can be somewhat difficult because of these special characters.XML Fundamentals August 1. However. &quot. That means that a CDATA section can have <. Solomon & Dr.

A fully qualified name is composed from a local name and a namespace. So in XML too we use fully qualified names. In XML the namespace simply put is a unique string. is not a good enough instruction: there can be dozens of tables called CUSTOMER. using the indication ButtonRenderer is not good enough. it is easy to see that instructing a database developer to write a SQL query against Table CUSTOMERS in a specific database. in the Oracle database it is the name of the schema. 2010 And one organization‟s customer can be quite different from another organization‟s. as there may be several classes called ButtonRenderer. we have the same thing. Slightly less simply put: the namespace identifier is a URI (Uniform Resource Identifier) according to the specifications laid down by the IETF (Internet Engineering Task Force. classes are used to construct objects that contain data and execute application logic. context based interpretations.ButtonRenderer. The fully qualified name for a class includes not just the name of the class. For example class PageRenderer may call upon class ButtonRenderer to render an instance of a Button. Without further indication. In Java programs. In Java the namespace is the package name.superui.sandbox.renderers. but clearly state our intentions. With XML. From the context of the document. These are quite simple. for our purpose at least: 8-8 .superui. we could easily misinterpret element names. but also the package in which it resides. When we speak about objects in the database.ButtonRenderer and my. However.Oracle 11g SOA Suite Handbook: Appendix B . Anyone class usually calls upon other classes to perform some task. we can derive that the charge element does not specify electrical information or the light brigade storming in but most likely the bill presented to the patient for this particular visit. RFC3986). for example org. A full identification of the table requires the schema in which it resides.renderers. Again. Thus programmers – and the JVM class loader – can distinguish between org. we should not rely on such subjective.XML Fundamentals August 1. We need to identify those XML element more accurately than by just using a simple name! Uniquely Identifying XML Elements Let‟s take a brief step away from XML. say when comparing a prison with a hospital.

and it is easier for people to remember a URI when it consists of meaningful or familiar components. digits.just like package names in Java . URI do not specifically refer to a resource that is accessible at a location that the URI seems to describe.patients PATIENT:UUID673215631265GEE A Namespace provides a container in which to collect names that for some reason belong together. any unique string will do: http://ourhospital. 2010 A URI is a . Many namespace identifiers in XML .ourhospital. and a few special characters.XML Fundamentals August 1. These names frequently share an owning organization.therefore include the URL for the website of the sensitive .Oracle 11g SOA Suite Handbook: Appendix B . not for accessing them. URIs are used to uniquely identifying resources. The IETF also remarks: A URI often has to be remembered by people. a domain or knowledge area or an industry. 15-9 .com/patient http://ourhospital.sequence of characters from a very limited set: the letters of the basic Latin alphabet. One straightforward way of making unique the elements you define in your XML documents is by using a namespace identifier that contains something unique to your organization or even to com. However.

We associate an XML element name with a namespace with this syntax: <patient xmlns="http://ourhospital. we should now speak about this element as { namespace identifiers are both defined in “Our Hospital”.com/patient"> Instead of just}patient. The http://ourhospital. Note: XML elements do not have to be in a namespace. with components listed in order of decreasing significance from left to right. This does not really mean anything . 2010 Namespaces for elements in different domains The URI syntax is commonly organized hierarchically. The patient is the local least not to software parsing the URI definitions. and describe various sub domains in that hospital. 8-10 .XML Fundamentals August and http://ourhospital. This is the Qualified Name of the element. often referred to as the QName. The local name of such unqualified elements is equal to their QName.Oracle 11g SOA Suite Handbook: Appendix B . There is no other connection between names in those two namespaces and the fact that their URIs have a partial overlap is meaningless to XML parsers and processors. it is just a convenient way of showing weak links at various levels.

2010 Having to qualify every XML name in this way would be dramatic: the document inflates even further. an element in whose content the prefixed markup occurs).Oracle 11g SOA Suite Handbook: Appendix B . we can work with simple prefixes and rely on several inheritance rules. It is up to the XML parser to associate each element via its prefix with the real namespace identifier.and some have become so commonly used for specific namespaces .that you would better refrain from using them for other purposes.XML Fundamentals August .such as xml and xmlns . the work involved is almost painful and the readability is negatively impacted.for example xsl (http://www. The namespace"> Some prefixes are reserved . So instead. Once a prefix has been associated with a namespace inside some element Prefixes allow us to use friendlier ways of associating names with namespaces. <hospital:patient xmlns:hospital="http://ourhospital. MUST have been declared in a namespace declaration attribute in either the start-tag of the element where the prefix is used or in an ancestor element (i.w3. The linking pin to make that possible is the namespace binding.e.with the namespace URI: <hospital:patient xmlns:hospital="http://ourhospital. the declaration somewhere in the XML document that associates the prefix .com/patient"> <hospital:personal> <hospital:firstName> 15-11 .org/2001/XMLSchema) and xhtml (for http://www. it can be used in all child elements.w3. unless it is “xml” or “xmlns”. Our patient element could be fully qualified with syntax like: <hospital:patient … > The prefix can be anything you like. xsd (for put it mildly. any string you fancy .again.

com/patient"> <personal> <firstName> Of course. The declaration of namespace bindings is usually done in the root element. an XML document may very well contain elements from different namespaces. We know that bloodReading is from the {http://who.xsd we have made the bloodPressureReading element available in the VeryPatient. without the colon and prefix. <patient xmlns ="http://ourhospital.typically the source of the largest portion of elements. we have a choice to make. we state that for this element and all its descendants the default namespace is set to http://ourhospital.Oracle 11g SOA Suite Handbook: Appendix B .org/medical} namespace. but can be done in any element. the default namespace simplifies things considerably. At this"> By simply using xmlns.XML Fundamentals August} namespace is not visible in the XML documents. We can select one as the (global) default namespace .com/patient. Namespace visibility in the XML instance document Through the import of the WHO-medic. In fact. It allows us to specify how instance XML documents can define bloodReadings inside the bloodReadings child in the patient element.xsd document. The default namespace is defined through a variation on the declaration we saw before: <patient xmlns="http://ourhospital. We can choose to leave it like that and add the knowledge and burden of both namespaces to the instance XML documents. If we choose to do the latter. 2010 We can also use the concept of the default namespace: any element that is not specifically prefixed or associated with a namespace through the xmlns attribute is in the default namespace if it has been defined. only the root element will need to be associated with the target 8-12 . the {http://who. A single namespace declaration in the root element of the document is all we need to associate all elements with the appropriate namespace. or we can decide to hide that complexity. The other namespaces can be associated with prefixes or be used as local default namespaces. Since many XML documents contain only elements from a single namespace.

org/2001/XMLSchema-instance" xsi:schemaLocation="http://ourhospital.w3. The outcome of our decision is declared using the elementFormDefault attribute in the schema element of all participating XSD documents.Oracle 11g SOA Suite Handbook: Appendix B .. With the attribute set to qualified. The instance documents will have no default namespace and only the root element patient is namespace qualified: <?xml version="1..0" encoding="windows-1252" ?> <xsd:schema xmlns:xsd="" xmlns:medic="http://who. That means that the namespace of each of the XSDs may be needed in the XML instance"> <personal> <firstName>John</firstName> .org/medical" targetNamespace="http://ourhospital. Note: all related XSD documents .. only the root element is namespace qualified and all other elements based on the schema are free of namespace qualifiers.need to have the same value set for this attribute. When this attribute is set to unqualified. and all other elements are without namespace qualification. all elements in the instance document are namespace qualified. 2010 namespace of the schema document in that case.XML Fundamentals August 1.xsd" xmlns:hospital="http://ourhospital. With the elementFormDefault set to unqualified in all XSD documents <?xml version="" xmlns="http://ourhospital. The namespaces for the imported XSDs are not visible in the instance document.0" encoding="UTF-8" ?> <hospital:patient xmlns:xsi="http://www.both the base document and all XSDs it imports" elementFormDefault="unqualified"> . 15-13 .

</bloodpressureReading > . the instance document has all elements namespace" elementFormDefault="qualified"> .. August 1.0" encoding="windows-1252" ?> <xsd:schema xmlns:xsd="" xmlns:medic="http://who.xsd" xmlns:medic="" targetNamespace=" VeryPatient.XML Fundamentals </personal> <bloodpressureReadings> <bloodpressureReading>.org/2001/XMLSchema" xmlns="" xmlns="" xsi:schemaLocation="http://ourhospital.0" encoding="UTF-8" ?> <patient xmlns:xsi="http://www. 2010 And with the Schema set to elementFormDefault qualified <?xml version="1...Oracle 11g SOA Suite Handbook: Appendix B . partly through the default namespace: <?xml version=""> <personal> <firstName>John</firstName> </personal> <bloodpressureReadings> <medic:bloodPressureReading> 8-14 .

In this next example. Again. 2010 <medic:dateOfReading>2008-12-29</medic:dateOfReading> The default value for the elementFormQualified is unqualified. but can be done in any" xmlns:hrm="http://www. This default is not overridden very frequently. the bloodPressureReading element defines a new (local) default namespace: http://who. We can select one as the (global) default namespace . This element and all of its children are in this namespace. Multiple Namespaces in an XML instance document Of course. <?xml version=" the source of the largest portion of bound to the prefix hrm. In the XSD documents used in the Oracle SOA Suite we usually will see this attribute set to qualified. The other namespaces can be associated with prefixes or be used as local default namespaces. The schema element in XSDs also has the attributeFormQualified we see an XML document with a global default namespace However. the default is unqualified. A secondary namespace is http://www.XML Fundamentals August 1. The declaration of namespace bindings is usually done in the root element. an XML document may very well contain elements from different namespaces. which similarly specifies for the attributes in the instance document whether or not they are namespace qualified.Oracle 11g SOA Suite Handbook: Appendix B .org/hrm"> <personal> <firstName>Mildred</firstName> <lastName>Huston</lastName> 15-15 . All unprefixed elements are in the default as for elementFormQualified.0" encoding="UTF-8" ?> <patient xmlns="http://ourhospital.

as inside bloodPressureReading this namespace is no longer known as the default namespace.staff member who did the reading --> <hrm:employeeId>64736</hrm:employeeId> </bloodPressureReading> </bloodpressureReadings> </patient> The child element age from the global default namespace that lives under bloodPressureReading. The prefix hrm that was defined in the root element of the document is available everywhere in the document and can therefore be used inside bloodPressureReading. A namespace can be bound multiple times to different prefixes in the same document: 8-16 . has to be explicitly associated with the http://ourhospital. 2010 <hospital:age xmlns:hospital=""> <dateOfReading>2008-12-31</dateOfReading> <systolicPressure>125</ systolicPressure> <diastolicPressure>85</diastolicPressure> August"> 58</hospital:age> <!-.XML Fundamentals </personal> <mailAddress> <hrm:city>Redwood Shores</hrm:city> <hrm:state>CA</hrm:state> <hrm:country>us</hrm:country> <hrm:street>Pancake Boulevard</hrm:street> <hrm:houseNumber>12</hrm:houseNumber> </mailAddress> <bloodpressureReadings> <bloodPressureReading xmlns=" namespace.Oracle 11g SOA Suite Handbook: Appendix B .

15-17 . The concept of qualified names and namespaces not only applies to elements but to attributes as"> . However.. <hospital:doctorVisit priority="normal" calendar:dateOfVisit="2008-12-31" xmlns:calendar="http://www. 2010 <?xml version="" xmlns:staff=" It has two attributes: priority and dateOfVisit. <hrm:city></hrm:city> <staff:city></staff:city> The two city elements in this document have the exact same fully qualified" xmlns:hrm="http://www. The first is not in any namespace.InternationalCalendarTaskForce. It is implied that these are both XML messages.XML Schema Definition The provisional service interface definition specifies an input and an output" encoding="UTF-8" ?> <patient xmlns=""> Here we see a doctorVisit element from a namespace bound to the prefix hospital. potentially different from the namespace of its owning element.Oracle 11g SOA Suite Handbook: Appendix B . XSD .XML Fundamentals August 1. Most attributes are in this unqualified state. The dateOfVisit attribute is associated with some specific namespace apparently linked to the fictitious International Calendar Task Force. as hrm and staff both resolve to same URI. Prefixes are nothing but shortcuts for the full URI. by prefixing its name. An attribute not explicitly associated with a namespace via a namespace prefix is not in any namespace (which is amounts to more or less the same thing as a big universal namespace with an empty string as identifier). an attribute can be associated with any namespace.

In general. a tree structure with properly opened and closed element tags. An XSD is an XML document . Without them. we have not yet determined how these messages are to be constructed. when we deal with XML documents.that describes the vocabulary for XML elements and attributes. The data model for XML documents is created using XML Schema Definitions . Any well-formed XML document has a single root element. we know little more than a database developer who knows a relational database is used. text content and attributes. Based on these designs for the XML documents.Oracle 11g SOA Suite Handbook: Appendix B .readable to humans and software . but does not have a database design. we can:   determine the validity of XML messages start building the software that needs to process the XML . 2010 However. But this is too little specific to start exchanging meaningful information or build software to process the XML documents. they can do things like:    Generate XML documents according to the Schema Definitions Support editing XML documents (with Code Completion and Instant Validation) Generate a User Interface for presenting and manipulating the content of XML documents 8-18 .XML Fundamentals <operation name="getPatientRecord"> <input message="PatientIdentificationInputMessage"/> <output message="PatientDataRecordOutputMessage"/> August 1.or XSDs. Once we have the XSD for the XML documents we will be dealing with. We need more specific rules to describe the structure. the data types and other constraints for the XML we know what information to expect and where to find it in the document Most (SOA) development tools can interpret XSDs. we know that they will follow the XML grammar rules.

child elements. 2010  Generate PL/SQL records or Java Classes that provide the native representation of the XML document . attributes and the order of all of these Types: primitive (built in) and user defined Rules or Constraints: default values.html for all details): String boolean Float Double Decimal Integer non-positive integer negative integer date time timeinstant timeduration recurringinstant uri-reference byte long 15-19 . valid value range or allowable values for 11g SOA Suite Handbook: Appendix B . optionality and updateability The table below lists the most important primitive data types define in the XSD specification (see XML Schema Part 2: Datatypes Second Edition http://www.XML Fundamentals August well as the code to unmarshall and marshall the XML documents to and from these native objects  Support creation of XPath queries for extracting information from XML documents based on the XSD  Allow visual construction of XSLT transformations from one XSD to another XSD documents define for a specific collection of XML Elements    Structure: elements. number of occurrences of child elements.

defined through the targetNamespace attribute in the schema element. <?xml version="1. 2010 XML Schema Definitions Let‟s look at a simple XSD document.0" encoding="utf-8" ?> <xsd:schema xmlns:xsd="http://www.w3. bound to the xsd" targetNamespace="http://www. This means that any occurrence of this { namespace .org/hrm }address Fundamentals Int Short binary token August It specifies the address element in the http://www. The XML elements in this document that are part of the XSD vocabulary itself are all from the namespace http://www.Oracle 11g SOA Suite Handbook: Appendix B . should conform to the rules in this" elementFormDefault="qualified"> <xsd:element name="address" type="physicalAddress"/> <xsd:complexType name="physicalAddress"> <xsd:sequence> <xsd:element name="postalCode" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string" minOccurs="0"/> <xsd:element name="country" type="countryCode"/> <xsd:choice> <xsd:sequence> <xsd:element name="street" type="xsd:string"/> <xsd:element name="houseNumber" type="xsd:string"/> 8-20" xmlns="http://www.

Oracle 11g SOA Suite Handbook: Appendix B . 2010 </xsd:sequence> <xsd:element name="poBox" type="xsd:string" /> </xsd:choice> </xsd:sequence> <xsd:attribute name="typeOfAddress" type="xsd:string" /> </xsd:complexType> <xsd:simpleType name="countryCode"> <xsd:restriction base="xsd:string"> <xsd:maxLength value="2"/> <xsd:enumeration value="nl"/> <xsd:enumeration value="us"/> <xsd:enumeration value="de"/> <xsd:enumeration value="be"/> <xsd:enumeration value="mx"/> <xsd:enumeration value="it"/> <xsd:enumeration value="dk"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> 15-21 .XML Fundamentals August 1.

the state element is optional. countryCode.Oracle 11g SOA Suite Handbook: Appendix B . It contains a number of child elements such as postalCode. Finally. 8-22 . The xsd:choice element specifies this mutual exclusiveness. a string. Two restrictions are defined: the countryCode is a string of no more than two characters and the value of countryCode must be one of the values defined in the enumerations. based on the physicalAddress type. city. 2010 XSD compared to UML Class Model and Entity Relationship Diagram The XSD declares the address element. However. the physicalAddressType also declares an attribute called typeOfAddress. The country element is based on a simpleType. Note: the first restriction is not very meaningful considering this second rule… The physcialAddressType then contains either a poBox element or a street and houseNumber . These must occur in this order.XML Fundamentals August 1. Next comes the definition of this complex type. state and country. The countryCode type is based on the built in simpleType string.

Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals August 1, 2010 An XML instance document with the { }address element has to abide by the rules laid down in the XSD definition - to be considered valid by XML processors that are aware of that schema:
<?xml version="1.0" encoding="UTF-8" ?> <address typeOfAddress="emergencyContact" xmlns=""> <postalCode>3456</postalCode> <city>Luik</city> <country>be</country> <street>Waffle Avenue</street> <houseNumber>123</houseNumber> </address>

A very special element we can use in an XSD document is the any element. We use it to specify the occurrence of a block of well-formed XML - XML content that conforms to the XML syntax rules - about which we otherwise almost nothing. The next snippet specifies that inside the patientType there can be an attachment element that contains well formed XML. What the structure or vocabulary for that content is unknown - it can be anything.
<xsd:complexType name="patientType"> <xsd:sequence> <xsd:element name="attachment" minOccurs="0"> <xsd:complexType> <xsd:sequence> <xsd:any minOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element>


Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals

August 1, 2010

In addition to the any element, there is the anyType type that can be used to specify both elements and attributes. This type does not constrain values in any way - and can be used for example when we have too little information or control to enforce a more specific type.

A complex type can be defined as an extension of an existing complex type - adding new elements to the set already defined in the base type. For example:
<xsd:complexType name="geoAddress"> <xsd:complexContent> <xsd:extension base="physicalAddress"> <xsd:sequence> <xsd:element name="geoCode" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>

Creating an element based on another element We have seen how an element can be based on a simpleType or complexType definition through the type attribute. The type needs to be a global type - that means a direct child of the schema element. Instead of basing an element on a type, we can also define an element as the image of another element. Suppose for example the imported Administration.xsd document contains a global element called bankAccount with embedded complexType. Now we want to define a child element bankAccount for the patientType, that has the exact same structure. We do not have to replicate the element from the imported schema, we can refer to that element, like this:


Oracle 11g SOA Suite Handbook: Appendix B - XML Fundamentals August 1, 2010
<?xml version="1.0" encoding="windows-1252" ?> <xsd:schema xmlns:xsd="" xmlns="" xmlns:hrm="" targetNamespace=""> <xsd:import schemaLocation="Administration.xsd" namespace=""/> <xsd:element name="patient" type="patientType" /> <xsd:complexType name="patientType"> <xsd:sequence> ... <xsd:element name="primaryBankAccount" ref="hrm:bankAccount" minOccurs="0" maxOccurs="3"/>

The ref attribute declares for the element it belongs to a reference to another element on whose definition it is based. Defining Constraints in Schema Definitions The XSD specification provides a number of ways in which we can define constraints the XML counterparts of Unique Key, Foreign Key and Check Constraints as we know them in the Oracle database. For elements we can specify the minOccurs and maxOccurs - defining thus the optionality and cardinality. We can also indicate a default value for elements. The fixed attribute can be used on an element to indicate that its value cannot be changed. We have seen how the simpleType countryCode was declared to create a restricted variation on the string type. We can define new simpleType elements that are based on existing type and add constraints to it. Such constraints include a set of allowable values (such as is the case for countryCode), a valid range, a regular pattern expression, the minimum and maximum length and the total number of digits. We can for example define a new type to base email address elements on:


A complex type can be defined as an extension of an existing complex type . 2010 <xsd:element name="emailAddress" type="emailAddressType"/> .([a-zA-Z0-9_-])+)+"/> </xsd:restriction> </xsd:simpleType> The key..XML Fundamentals August 1. With unique we declare uniqueness for one field or a combination of fields. <xsd:unique name="patientUniquenessConstraint"> <xsd:selector xpath=".a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(([a-zA-Z0-9_])*\. uniqueness and referential constraints. With keyref we can indicate a reference from an element to the key of another (or the same) element. Through a key we can specify for an element which of its fields provide(s) an identifying.adding new elements to the set already defined in the base type. unique and keyref elements allow us to declare identity. referenceable value. For example: 8-26 . Note that XPath is an XML query language that we discuss later in this book. <xsd:simpleType name="emailAddressType"> <xsd:restriction base="xsd:token"> <xsd:pattern value="([\.Oracle 11g SOA Suite Handbook: Appendix B .//patient"/> <xsd:field xpath="firstName"/> <xsd:field xpath="lastName"/> </xsd:unique> This snippet declares a uniqueness constraint for the patient element on the combination of the firstName and lastName child elements.. With the frequent use of John Doe for otherwise hitherto unidentified patients. this constraint will probably not turn out to be a realistic one.

When processing an XML instance document. These XSDs describe elements in namespaces . the QName of the elements in the document is compared with this list of registered schema based elements.XML Fundamentals August 1. 2010 <xsd:complexType name="geoAddress"> <xsd:complexContent> <xsd:extension base="physicalAddress"> <xsd:sequence> <xsd:element name="geoCode" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> Associating XML document with XSDs The XML processor will typically know of one or multiple XSD document that have been registered with it. Any element in the XML instance document that can be matched will be validated against the schema definition. 15-27 .Oracle 11g SOA Suite Handbook: Appendix B .with each XSD providing the specification for one or more fully qualified elements.

XML Fundamentals August 1.w3.Oracle 11g SOA Suite Handbook: Appendix B the XML instance document can contain an explicit reference to one or more XSD definitions.w3.. Some tools seem to prefer this explicit association <address xmlns:xsi="http://www. The attribute is 8-28 .org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.implicitly referenced by XML instance documents Administration. 2010 XSD documents describing elements in Namespaces .org/hrm"> <postalCode>.xsd" xmlns="http://www. The hint about the schema location is passed in the form of a schemaLocation attribute that is defined in the http://www.

we do not have stick to single XSD document with all elements in any single domain in a single file. Managing XSDs and XSD dependencies We use XSD documents to describe the XML vocabulary we want to use in a specific business domain. . and has to be preceded by a namespace binding .xsd which contains the patient element that forms the basis for the PatientDataRecordOutputMessage used in the getPatientRecord service operation.Oracle 11g SOA Suite Handbook: Appendix B . such domains can be quite large with substantial numbers of elements. For example..usually to the prefix xsi. we can create an XSD document VeryPatient. Of course. The XSD specification describes the include and import elements that allow us to manage element and type definitions in multiple documents.XML Fundamentals August 1.. <xsd:element name="patient" type="patientType" /> <xsd:complexType name="patientType"> 15-29 . Fortunately. 2010 included in the root element of the instance document." xmlns=" that is imported into the VeryPatient. include is used for XSDs with the same targetNamespace as the base XSD.w3. The patient element is based on the patientType complexType that contains among others the mailAddress element which is based on hrm:physicalAddress type .org/hrm" The definition for this type is in a separate XSD document. 8-30 . However. while import is used with external schema definitions describing elements from a different namespace.xsd" namespace="http://www.Oracle 11g SOA Suite Handbook: Appendix B . Similar to the xsd:import. The physicalAddress type is bound to the {http://www.from a different namespace and defined in a different XSD"/> The import element tells any processor interpreting the XSD document in which it is contained that it should read the contents of the imported XSD document and merge it with the current XSD‟s definitions.xsd whether the physicalAddress type was in that XSD itself or in some imported XSD. This means that it is transparent to anyone using the VeryPatient. the xsd:include instruction also instructs XSD processors to read XSD element and type definitions from the indicated external XSD document. 2010 <xsd:element name="personal" type="personNameType" maxOccurs="1" minOccurs="1"/> <xsd:element name="mailAddress" type="hrm:physicalAddress" minOccurs="1" maxOccurs="3"/> .org/hrm} namespace (its prefix hrm is declared at the top of the XSD document: <xsd:schema xmlns:xsd="http://www.xsd schema: <xsd:import schemaLocation="" xmlns:hrm="http://www.XML Fundamentals <xsd:sequence> August 1.

When you create a new XML document in JDeveloper.xsd we have made the bloodPressureReading element available in the the very least the data that is interchanged between systems and published by (web) services. JDeveloper has support for the creation of XSD documents.Oracle 11g SOA Suite Handbook: Appendix B . making the XML editing a productive task. Together the XSDs describe all business data of interest . Note that these features are available for any XML document that is associated with XSD documents. It will provide instant validation. much like the management of the corporate data model. you can base it off an XSD file and have JDeveloper generate the document structure with all elements and attributes already inserted. The ability to link XSDs is essential in building a structure of Schema Definitions that is manageable.xsd document. It allows us to specify how instance XML documents can define bloodReading elements inside the bloodReadings child in the patient element. The XSD documents form an important asset for an organization that adopts SOA. More specific type and element definitions that are used for particular applications and services are defined in yet lower levels. The namespace associated with the Schema Definition derives its name from the business domain. the option XML Schema can be used to create an XSD. This approach allows for OO like reuse and inheritance of business object definitions. From the New Gallery. 15-31 . refinement and composition of elements and types is done at lower levels in the XSD hierarchy in XSD documents that import the business objects. The editor offers a design view in addition to the source view. 2010 Managing XSD documents is very important. At the root you will find entities or business objects from specific business domains. again importing from the more generic Schema Definitions. Namespace visibility in the XML instance document Through the import of the WHO-medic. among other features. Extension.XML Fundamentals August 1. drag & drop from component pallet support and code completion. Category XML. Many organizations use hierarchies of XSD documents. either explicitly through the xsi:schemaLocation attribute or because of namespaces in the XML document that are described in XSD documents that have been registered with JDeveloper. The XSD editor is fully aware of the structure of an XSD document and provides instant validation and code completion.

The next section introduces the XSD phenomenon. Most of the same logic and steps are involved with each of these data design techniques. a document that describes the data design of XML elements.Oracle 11g SOA Suite Handbook: Appendix B . for example when we go from one domain . In fact. manually creating XML files is occasionally required of us. choose XML Document and press OK. Creating and Editing XML documents in JDeveloper 11g Creating XML documents is a task usually performed for us by automated means.though without actual content and values. JDeveloper 11g‟s XML Editor has useful features such a checks on well-formedness (does the document comply with the XML syntax rules) and validity (does the document satisfy the rules laid down in the XML Schema Definition.service calls in XML. see next section) and productivity enhancers like XML element tag completion. However. JDeveloper can also create an XML document based on what is called an XML Schema Definition (XSD). most IDEs including JDeveloper have fairly advanced XML editing capabilities. it is fairly easy to largely convert data designs created in one technique into one of the others. In addition to specialized XML editors of which there are plenty available. And this is needed on a regular basis.XML Fundamentals August 1. use of SQL/XML queries. for example for testing purposes. Such means include text-file to XML converters. Java programs that construct XML documents from string data or Word processors that save files in XML the other . reformat and code completion. management of configuration files and the development of XML documents that . JDeveloper creates such an XML document will all required structure (elements and attributes) already in place . Create XML Document From the New Gallery. 2010 The XML Schema Definition is to XML what the Class Diagram is to Java and the ERD or logical data design to relational databases. 8-32 .the implementation of a service in Java or SQL & PL/SQL .

2010 Enter the name for the XML Document: Calendar.XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B . Now create a small XML Document that contains some birthdays: 15-33 .xml and press OK. The XML Editor opens with an (almost) empty XML Document.

saving some typing. We can make it add the end tag for any element we add to the document.XML Fundamentals August 1. We activate that behavior from the Preferences window: 8-34 . 2010 Note: the XML Editor can help us a little.Oracle 11g SOA Suite Handbook: Appendix B .

you can quickly have it reformatted using the Reformat option in the Right Mouse Button Menu: The result: The XML Editor has one other quite important feature: it checks the correctness of the XML document. 15-35 .Oracle 11g SOA Suite Handbook: Appendix B . It will inform you in the structure window (or when you build the file or the project) of violations against rules of Well-Formedness. 2010 Note: if you do not like the layout of your XML document.XML Fundamentals August 1.

XML Fundamentals August 1. since we have not specified what valid is. from the Database Design we will create another XSD document that finally is used to produce Java class definitions.a simple variation on the Patient data record. The BloodPressureReading class contains some properties pertaining individual blood pressure 8-36 . from a Java Class model to an XSD and an Oracle Database Design.Java to XSD to Database and vice versa We will make a round trip.Oracle 11g SOA Suite Handbook: Appendix B .bloodPressureReadings and doctorVisits. Demo: Round Trip Data Design . A Patient class with two private collection properties . Step one: from Java to XSD First we create the Java class model . 2010 At this point. Note: this round trip is not something you would knowingly do it merely goes to show the similarities between the three data design approaches involved. the editor does not know about Validity. Then.

The one we are interested in is called GetPatientDataRecordService. Finally there is a Service class GetPatientDataRecordService that has a getPatientDataRecord() method that returns a Patient object.we do not care about those at this point. that tries to do full justice to the List interface. JDeveloper will now generate a number of files to construct a Web Service based on GetPatientDataRecordService class. When you open that file. In the wizard that opens.4 with support for JSR 181 JAX-RPC Annotations). Simply select Create Web Service from the Right Mouse Button (RMB) Menu. BloodPressureReading and DoctorVisit . Accept the default Service and Port-name .as well as types list and collection for a fairly complex implementation of the collections bloodPressureReadings and doctorVisits. Let‟s use a very simple one: the Create Web Service wizard in JDeveloper. 15-37 . and the same applies to the DoctorVisit class. select the first Deployment Platform option (J2EE 1. 2010 readings.wsdl.XML Fundamentals August 1. Ensure that in the step Message Format the checkbox Generate Schema with Qualified Elements is checked. Press Finish.Oracle 11g SOA Suite Handbook: Appendix B . Simplified Patient Java Class Model There are several automated ways to turn a class model into an XSD document. the types element contains the XSD definition for elements called Patient.

you can also generate an XSD document for the classes in the Simplified Java Class Model: public static void main(String[] args) throws JAXBException. BloodPressureReading. context. 2010 An alternative way is using the JAXB facilities.class."). 8-38 .Oracle 11g SOA Suite Handbook: Appendix B . } We can easily create an isolated XSD document based on the types section in the WSDL.class. public Result createOutput(String namespaceUri.newInstance(Patient. } } JAXBContext context = JAXBContext. With the next Java code snippet. String suggestedFileName) throws IOException { return new StreamResult(new File(baseDir. IOException { class MySchemaOutputResolver extends SchemaOutputResolver { File baseDir = new File(". DoctorVisit.XML Fundamentals August 1.generateSchema(new MySchemaOutputResolver()). suggestedFileName)).class).

XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B . 2010 Graphical view of the Simplified Patient XSD document 15-39 .

relational way. 2010 For our next stage we go to the database.. One of the things XMLDB knows how to do is store and retrieve XML based data and bridge the gap between the world of SQL and relational data on the one hand and XML based data and querying (XPath and XQuery) on the other. genbean => FALSE . we need register an XSD document with the database. XML documents can be stored by XMLDB as documents . To register a Schema Definition with the database. This call will create tables and object types in the database schema for the user who executes this operation. In order to be able to store XML in this latter. gentypes => TRUE . </xsd:schema>' -. perform the following call: BEGIN DBMS_XMLSCHEMA. schemadoc => '<xsd:schema .or can be shredded into individual relational bits and pieces .the actual contents of the XSD document . a rich infrastructure for dealing with XML. The XSD document itself will be registered and can be looked up in the data dictionary view USER_XML_SCHEMAS. It also creates a number of database Object Types act as the glue between the XML and the tables. 8-40 .XML Fundamentals Registering the XSD with the database August 1. gentables => TRUE ). The Oracle RDBMS comes with XMLDB. local => TRUE .with basically mapping an XML Element to a relational Table. XMLDB will then generate a bunch of tables that can hold and produce the data from XML documents based on that Schema ( schemaurl => 'http://our..xsd' .Oracle 11g SOA Suite Handbook: Appendix B .

child elements detail tables with a foreign key to their parent element.blogspot. Some of the XSD constraints can be turned into database constraints . 2010 Note: you can add annotations to the XML Schema that you register to instruct the registration mechanism in use of specific database types. Another way of creating the database design could be using an XSL-T stylesheet that transforms the XSD source into a DDL output. name number(10) varchar2(200) varchar2(4000) 15-41 . such as NOT NULL constraints . See for an example this blog article: http://annlewkowicz. It can be called to generate an XSD document for an object type and all of its associated types. Elements without content or attributes and attributes convert to columns.html .Oracle 11g SOA Suite Handbook: Appendix B .such as Oracle JPublisher.XML Fundamentals August 1. From database design to XSD Now for the return trip. Starting from the database we can have an XSD generated. Elements with child-elements or attributes typically will become tables. adding database constraints and overriding naming derivation with names of your choosing. based on Object Types or Table and View definitions.such as minOccurrences > 1. For example with these object types: create type hospital_visit_t as object ( date_of_visit date . Several tools can do this for you .com/2008/01/create-ddl-from-xsd-file-part-ii.and probably better than any automated tool. Of course the mapping from XSD to Database is one you could easily do by hand as well . The Oracle database itself also provides some support: the DBMS_XMLSCHEMA package provides the generateschema function. summary ) create type hospital_visit_tbl_t as table of hospital_visit_t create type patient_t as object ( id .while others cannot be implemented using declarative constraints . XMLSpy and XMLFox.

0 Content Model from XML Schema. it will generate Java Classes that are derived from the XSD type and element definitions. from the Toplink/JPA category in the New Gallery. XPath is used in BPEL process in Assign activities. birthdate varchar2(10) date August 1.0. See http://www. is used in SCA and SDO (Service Data Objects). hospital_visits hospital_visit_tbl_t ) This call SELECT DBMS_XMLSCHEMA. 'PATIENT_T') FROM DUAL returns an XSD document that describes this data structure very well. core to XQuery and heavily used in SQL/XML. several options are available to map from XSD definitions to Java Classes.w3. A wizard appears that asks you for the location of the XSD document. XPath is also a key element of XML Stylesheet Language Transformations (XSLT). XPath is a language for addressing (finding and either retrieving or manipulating) values in XML sources. When you select the XSD and complete the wizard. Again.XML Fundamentals . In JDeveloper. through the XMLType in PL/SQL and for example using JAXP in Java. initials .generateschema('SCOTT'. XPath is supported in Javascript. 2010 .Oracle 11g SOA Suite Handbook: Appendix B . Producing Java Classes from an XSD The last stage of our voyage is from XSD to Java Classes.0 (commonly referred to as XPath) is a W3C standard. you can select the option JAXB 2. the SQL variant for dealing with XML in relational databases. the Java Specification for XML Binding and more specifically the Toplink/EclipseLink support for Java/XML mapping. We will use JAXB 2. 8-42 .org/TR/xpath for the specification. Using XPath to query XML data XML Path Language 1.

There are different types of nodes.12"> <dateOfVisit>2010-12-14</dateOfVisit> <summary>kidney surgery</summary> 15-43 .as in URLs . 2010 From the W3C specification: “XPath gets its name from its use of a path notation . Zhivago"> <dateOfMeasurement>2010-11-22</dateOfMeasurement> <whatWasMeasured>BodyHeight</whatWasMeasured> <measuredValue>184</measuredValue> <unitOfMeasurement>cm</unitOfMeasurement> </physicalCharacteristic> <hospitalVisit cost="312. we construct an expression (location path) that accesses a node or set of nodes..Oracle 11g SOA Suite Handbook: Appendix B . attribute nodes and text nodes.54"> <dateOfVisit>2010-11-22</dateOfVisit> <summary>Dead upon Arrival. including element nodes. Take this XPath expression that addresses all name nodes under the root patient element: /patient/name and apply it to this XML document: <patient> <name>John Doe</name> <physicalCharacteristic staffMember="Doctor X.] XPath models an XML document as a tree of nodes.XML Fundamentals August 1. in the XML source we have the expression act on.” Using XPath‟s notation.[.</summary> </hospitalVisit> <hospitalVisit cost="2580. XPath defines a way to compute a string-value for each type of node.for navigating through the hierarchical structure of an XML document. possibly with their child nodes.

a string between two virgules or backslash characters . 2010 The result will be <name>John Doe</name>. as that is the only name node available. If I want to have the value of the <name> node. but starts at 1. To get the cost for every hospitalVisit in the document. or better stated: the value of text node that is the child of the <name> node. like the XPath expression evaluates to an XML node set (which can be empty.Oracle 11g SOA Suite Handbook: Appendix B . the XPath expression should be: /patient/name/text() XPath expressions address attributes using the @ operator. This notation by the way is short for: /patient/hospitalVisit[position()=2]/dateOfVisit Here we see that the square brackets are a construction for specifying a Boolean expression that must evaluate to true for a node in order to be returned by the XPath processor. For example the expression: /patient/hospitalVisit[2]/dateOfVisit Returns <dateOfVisit>2010-12-14</dateOfVisit>. Note: the indexing is not zero-based. It is important to realize that such search conditions can be applied to every step in the location 8-44 . can contain a single node or may contain multiple nodes). Note: every location step . use: /patient/hospitalVisit/@cost To access a specific element in a node set.XML Fundamentals </hospitalVisit> </patient> August 1. we can use an array like notation using the square brackets. as that is the dataOfVisit child element in the second hospitalVisit element.

Oracle 11g SOA Suite Handbook: Appendix B . The function position() by the way is one of the many built-in XPath functions that can be used in XPath expressions. WSDL. all readily available from the XPath expression builder tool.</summary> </hospitalVisit> XPath has a lot more to offer than these examples illustrate. along with possible namespace details. When an XML document is open in the source editor . /patient[gender='M']/hospitalVisit[@cost > 400 and contains(translate(summary. JDeveloper has built in XPath search support. SOAP and even JSPX files .0 does not have a function that converts a string to only lowercase characters.XML Fundamentals August 1. XPath 1.including XSD. A slightly more complex example that returns all hospitalVisit elements for a patient whose gender is M(ale).'K'. and can be extended with vendor or even user defined functions. where the visit was more expensive than 400 and its summary contains the word “kidney”. Note that the function translate is used here to cater for the fact that kidney may have been spelled with a capital K.'k'). The Oracle SOA Suite contains a substantial number of additional XPath functions.'kidney')] The result of this XPath query: <hospitalVisit cost="2580. an XPath expression is entered. XPath expression can move between nodes in many advanced ways to retrieve data according to very complex requirements. XPath supports operands and functions to manipulate values. 15-45 .. In the XPath Search tool. and the search can be executed. 2010 path. Using no fewer than thirteen axis specifications for example.12"> <dateOfVisit>2010-12-14</dateOfVisit> <summary>kidney surgery.the option XPath Search is available from the Search option in the main menu.

XML Stylesheet Language for Transformations XML documents represent data. XSLT is a language. even though a plethora of tools. Data is queried from the source document using XPath expressions. 8-46 . platform. platforms and applications know how to interpret XML in general does not necessarily mean they all work with the same XSD definitions as well. organized in some predefined. environments. protocol and vendor borders as few mechanism for recording data are as generic and technology-free as XML. In many situations. data in XML documents needs to be transformed before it can be sent or processed. usually queried from the source document. XML documents are used frequently to communicate data. that prescribes the XML elements and attributes to produce and the values for these to write. between automated environments and potentially across technology. Note that usually this transformation takes an XML document and produces another XML document. itself written in XML. 2010 XSLT . structured way. However. Source and target documents are generally based on different XSD documents.XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B .

the contents of the template is processed. At the heart of XSLT processing are templates: snippets that can be matched against sections in the source document based on XPath expressions. The XSLT stylesheet: contains static XML to send into the output. <?xml version="1. and produces XML output document.output information --> </xsl:template> </xsl:stylesheet> An XSLT stylesheet is an XML document containing: a <xsl:stylesheet> root element declaring the xsl namespace prefix with http://www. When a template is matched.Oracle 11g SOA Suite Handbook: Appendix B . RSS..XML Fundamentals August 1. The XSLT stylesheet typically contains the root template . uses XPath expressions to get data from the XML source and uses XSLT logic (if-else) and operators (for-each) to process the XML source.> <xsl:template match="XPath"/> <! and one or more <xsl:template> elements and other XSL elements defining transformation rules.and starts the creation of the output document: 15-47 . 2010 XSLT processing takes an XML source document and an XSLT stylesheet.a template that matches the root node of the source document . The XML output can be XHTML. SVG.0"?> <xsl:stylesheet . JSPX or any other XSD based XML..w3. XSL-FO (=> PDF).

</summary> </hospitalVisit> <hospitalVisit cost="2580. Zhivago"> <dateOfMeasurement>2010-11-22</dateOfMeasurement> <whatWasMeasured>BodyHeight</whatWasMeasured> <measuredValue>184</measuredValue> <unitOfMeasurement>cm</unitOfMeasurement> </physicalCharacteristic> <hospitalVisit cost="312.Oracle 11g SOA Suite Handbook: Appendix B . regardless of the contents and size of the source document): <root>output</root> If we take the Patient document as the source again: <patient> <name>John Doe</name> <physicalCharacteristic staffMember="Doctor X.12"> <dateOfVisit>2010-12-14</dateOfVisit> <summary>kidney surgery</summary> </hospitalVisit> </patient> 8-48 . 2010 This template will match against the root node of any source document and will produce the following result document (always the same.54"> <dateOfVisit>2010-11-22</dateOfVisit> <summary>Dead upon Arrival.XML Fundamentals <xsl:template match="/"> <root>output</root> </xsl:template> August 1.

2010 and try to design the XSLT stylesheet that will create an output document that looks as follows: <?xml version = '1.Oracle 11g SOA Suite Handbook: Appendix B .0' encoding = 'UTF-8'?> <customer name="John Doe" height="184"> <consults> <consult> <notes>Dead upon Arrival.0" xmlns:xsl=""> <xsl:template match="/"> <customer> <xsl:attribute name="name"> <xsl:value-of select="/patient/name"/> </xsl:attribute> <xsl:attribute name="height"> <xsl:value-of select="//physicalCharacteristic[whatWasMeasured/text()='BodyHeight']/measuredValu e"/> 15-49 .0" encoding="windows-1252" ?> <xsl:stylesheet version="2.w3.</notes> </consult> <consult> <notes>kidney surgery</notes> <specialDate/> </consult> </consults> </customer> We will come up with the following XSLT stylesheet: <?xml version="1.XML Fundamentals August 1.

The value for this attribute is derived using a somewhat interesting XPath expression: //physicalCharacteristic[whatWasMeasured/text()='BodyHeight']/measuredValue. (The <xsl:for-each select=""> element instructs the XSLT processor to loop over the node set returned by the XPath 8-50 .the root note in the source document.Oracle 11g SOA Suite Handbook: Appendix B . 2010 You will notice the template that matches on the XPath expression '/' . The template then creates the <consults> element. A second attribute called height is create on the customer element.XML Fundamentals </xsl:attribute> <consults> <xsl:for-each select="//hospitalVisit"> <consult> <notes> <xsl:value-of select="summary"/> </notes> <xsl:if test="dateOfVisit='2010-12-14'"> <specialDate/> </xsl:if> </consult> </xsl:for-each> </consults> </customer> </xsl:template> </xsl:stylesheet> August 1. Using the xsl:forEach instruction.through the xsl:attribute instruction to the XSLT processor . This template creates the customer element in the result document.that has name as its name and the value of the (first) name element under the (first) patient element under the root. It queries the value of the measuredValue child element under the physicalCharacteristic element that has another child element whatWasMeasured with a text value of BodyHeight. it queries the collection of hospitalVisit child elements under the current root. Then it creates a new attribute .

The latter inspects an XML instance document and derives an XSD that describes the structure of the XML document. The instruction <xsl:if test=""> can be used to build in that conditionality.create XML Document from XML Schema . Use Include and Import to add XSLT templates from external documents (just like XSD). RTF and others JDeveloper support for XSD and XSLT JDeveloper provides a number of advanced features . When a visit to the hospital takes place on that day. Miscellaneous Creating comments is done using <xsl:comment>. The former feature . XSLT functions are available like document(). system-property(). Sometimes a section of the XSLT tree should only be processed under certain most XSLT processors (add custom functions). XSL-FO is XSL-T‟s little brother for describing the layout of a document (FO= Formatting Objects).that make life a lot easier.Oracle 11g SOA Suite Handbook: Appendix B . This element gets a notes child element for which the value is queried through the xsl:value-of instruction that uses the XPath query expression summary -the value of the element called summary.otherwise found in commercial XML editors .support for addition of user defined functions . XSL-FO can be converted to PDF.XML Fundamentals August 1. key() etc . current().is quite useful too: it generates an XML document with sample data based on a selected XSD document. it creates a consult element in the output document. It is a bit like taking the outcome of a complex SQL query can creating the DDL to create the underlying including a <specialDate> element. 15-51 . SVG. My personal favorites are 'Create XML Document from XML Schema' and even more 'Create XML Schema from XML Document'. C# and many other languages. Oracle Database. The test attribute contains an XPath expression that should evaluate to a boolean value. it should be highlighted . 2010 expression in the select attribute) For each such child element found. In this case we assume that 14th of December is a very special day. Java. format-number(). XSLT is supported in JavaScript. Extensible .in addition to the over 100 built in XPath functions.

Web Services We now take a closer look at the interface definitions that are drawn up for web service. We have earlier on seen the beginning of this contract: <operation name="getPatientRecord"> <input message="PatientIdentificationInputMessage"/> <output message="PatientDataRecordOutputMessage"/> <fault message="UnknownPatientIdFaultMessage" name="UnknownPatientId"/> 8-52 .Oracle 11g SOA Suite Handbook: Appendix B . 2010 JDeveloper provides the XSLT Data Mapper tool that enables you to create an xsl file to transform data from one XML Schema to another. An XSL Map is an annotated XSL Stylesheet .XML Fundamentals August 1.that JDeveloper can represent and edit in a visual way.

Abstract Service Interface: the portType We have talked about a specific operation the Patient Data Service should provide: getPatientRecord. or rather the physical endpoint (address) where the service can be invoked in combination with the protocol to be used for invoking the service. his Service may very well offer additional operations as well. WSDL is a W3C standard. input and output messages and faults. for example based on Java. as it specifies the abstract service interface that is on offer from the WebService. <portType name="SimplePatientRecordDataInterface"> <operation name="getPatientDataRecord"> <input message="tns:PatientIdentityRequestMessage"/> 15-53 . HTTP or MIME. frequently pronounced as whiz-dul). However.1 release of WSDL supported by the SOA Suite. Note that we will focus on the 1. including operations.XML Fundamentals August 1. A WSDL document describes the functional interface. It is up to the port elements to hook up the implementation of this abstract interface and its operations.and each binding can be exposed at one or more endpoints. JCA and JMS. The WSDL document contains the portType element. It also describes the implementations of the interface. Faults (referring to SOAP faults here) are the web service equivalent of the exception in languages like PL/SQL or Java. output and fault) involved with those operations.0. just as a Java Class may contain (and typically does) multiple methods and a PL/SQL Package provides more than one procedure.Oracle 11g SOA Suite Handbook: Appendix B . WSDL has extension points that allow definition of other binding types. a named set of abstract operations and the abstract messages (input. 2010 <fault message="NoUniquePatientMatchFaultMessage" name="NoUniquePatientMatch"/> </operation> This snippet is part of a so called WSDL document (WSDL is Web Service Definition Language. An interface can be bound to multiple to multiple protocols . originally for defining Web Services but today used for almost any kind of service . see also Chapter 17). Database APIs and RESTful services (with WSDL 2.such as SOAP.including Java interfaces. The portType element is very similar to the Java Interface artifact.

We first need to further specify the functionality of the getPatientRecord operation. Multiple part elements can be used when a message has several unrelated or at least logically separate units. Each part can be seen to represent a parameter in the operation request or response. The input and output element each have a message attribute. 2010 Message Definition We are nowhere near the point where we can or should start talking about the implementation details such as the end point for his service. sticking with single-part messages is less complex and less likely to have you run into tool limitations. For the “document literal (wrapped)” style service (which we will work with most of the time).Oracle 11g SOA Suite Handbook: Appendix B . by defining what the structure will be of the input and output messages. This attribute refers to a message element defined in the WSDL document or an external XSD: <message name="PatientIdentificationInputMessage"> <part name="PatientIdentificationPart" element="imp1:PatientIdentification"/> </message> <message name="PatientDataRecordOutputMessage"> <part name="PatientDataRecordPart" element="imp1:PatientDataRecord"/> </message> A message can consist of multiple parts. the WS-I Basic Profile specifies that at most one part is allowed.XML Fundamentals <output message="tns:PatientDataRecord"/> </operation> </portType> August 1. In general it seems that unless there is a real need for using multi-part messages. 8-54 .

It‟s like agreeing on the form that we will fill out and send to some agency to make a request but not discussing the address we should send the form to . For reasons of loosely coupling and reuse of type definitions as well as keeping the WSDL document" schemaLocation="Patient.and Margaret‟s team can commence with software invoking that service.that is what the service and port. working with external XSDs is preferable over including type definitions inside the WSDL document.Oracle 11g SOA Suite Handbook: Appendix B . This section can contain XSD style element and type" xmlns="http://www.nor 15-55 . Frank and his team can start working on the implementation . they have the abstract interface for the getPatientRecord operation in the PatientDataService.w3.XML Fundamentals August 1. When they have done so. 2010 Each part is based on either a type (for Remote Procedure Call or RPC style Services) or an element (for the document literal style services we will primarily deal with) that is defined in the <types> section of the WSDL"> <import namespace="http://ourhospital.elements are for . At that point. The precise physical address can be determined later on. The two first need to agree on how the service will be called. Well.xsd"/> </schema> </types> Frank and Margaret need to flesh out the structure of the PatientIdentification and PatientDataRecord elements in the Patient. almost. or import one or more external XSD to fulfill the contract .xsd. <types> <schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ourhospital. What we have not described yet is how the request and the response are communicated. Through the operation and message elements together with any referenced XSDs we have specified the XML structure for the requests to and responses from the service. but it would be useful to know the protocol via which the service is to be invoked.

this time the XML document that contains at its core a message being transmitted. It is another W3C standard that describes the structure of an XML document. enveloped by meta-data pertaining to the transmission itself. While RESTful Service APIs are quickly becoming more popular. many tools including the Oracle SOA Suite when it comes to external Web Service calls primarily speak SOAP (formerly known as the Simple Object Access Protocol but today just referred to as SOAP). SOAP .XML Fundamentals August 1.for example the address to which send any replies -. Note: we discuss SOAP 1.the XML transmission language SOAP describes the meta-details for sending messages between service and requesters.Oracle 11g SOA Suite Handbook: Appendix B .2 as that is the default version used in the Oracle 11g SOA Suite. including addressing information . transaction coordination 8-56 . A SOAP message in its simplest form looks like this: Structure of SOAP messages The SOAP header can contain various types of meta-data. 2010 thinking about the envelope we should wrap the form in and the fact that we may need to provide a return address to ever receive the reply from this agency if they cannot give one straightaway but have to come back to it later.

org/soap/http"/> <operation name="getPatientDataRecord"> <soap:operation soapAction="getPatientDataRecord" /> <input> 15-57 . JCA with SOAP being the most prominent among them: <binding name="PatientDataServiceSoapHttp" type="tns: PatientDataServiceInterface"> <soap:binding style="document" transport="http://schemas.Oracle 11g SOA Suite Handbook: Appendix B .xmlsoap. <env:Envelope xmlns:env="http://schemas. The Body element is the container for the actual payload sent in the SOAP"> <env:Header/> <env:Body> <ns1:patientIdentification> <ns1:patientId>3232</ns1:patientId> </ns1:patientIdentification> </env:Body> </env:Envelope> Of course the structure of SOAP messages is the same. Several options are available for }patientIdentification root element with its contents. The How and Where in the WSDL contract The Binding element in the WSDL document is used to describe the fact that the specific operations in the service are callable via a specific protocol binding and data format. the payload is the {http://ourhospital.xmlsoap. regardless of whether the messages contain a request or a reply. such as the root Envelope element or the Header and Body elements." xmlns:ns1="http://ourhospital.XML Fundamentals August 1. 2010 details and authorization tokens. Namespace can be declared at various levels. including HTTP. In the example below.

ibm.xmlsoap.refer to the paper mentioned above for details. For the purpose of this book . The value specified for soapAction must be included in the HTTP Request Header as SOAPAction. 8-58 .Oracle 11g SOA Suite Handbook: Appendix B . See this almost classic paper for details: http://www. we need to include a child operation element inside}binding since the prefix soap is bound to this namespace .XML Fundamentals <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> August 1. For each operation in the referenced portType that we want to support through the binding. Note: This soap:operation element must also have a soapAction attribute when the transport is http.indicates the protocol. The input and output elements are finally used to specify whether the SOAP binding has a literal or encoded use for the parameters.the element that contains the abstract functional interface that declares the available operations. The alternative. is rapidly getting out of fashion.and almost always in other cases . The binding element links a portType to a protocol and a style of message formatting. 2010 The type attribute in the binding element refers to a portType element . The name attribute on the operation element refers to the name of one of the operation inside the referenced portType. will be set to . We will always use literal . The soap:binding element specifies the format through the style attribute. In this case we have defined the binding of the PatientDataServiceInterface portType to the SOAP protocol using a document style message this case soap:binding or {http://schemas. The child element of the binding element .

Note the three sections that describe the what [functionality is offered by the service]. the how [can this functionality be invoked in terms of protocol and message format] and where [at which physical end point can the service be contacted] of the service The WSDL document will be completed with the Service element that finally assigns physical address details to each of the binding elements in the document.Oracle 11g SOA Suite Handbook: Appendix B .XML Fundamentals August 1. 2010 Overview of the structure of WSDL documents. Here is the Service element for the contract Frank and Maggie are drawing up: <service name="PatientDataService"> <port name="PatientDataRecordServiceSoapHttpPort" binding="tns: PatientDataServiceSoapHttp "> <soap:address location="URL_To_Be_Defined"/> 15-59 .

JDeveloper provides a WSDL editor. 8-60 . with both Source and Design view.Oracle 11g SOA Suite Handbook: Appendix B . The location is therefore not yet defined in the WSDL. However neat this UI. However. based on for example BPEL process and Mediator service definitions. The binding tells us how to invoke the service operations . the latter offering a graphical overview of the WSDL with drag and drop support for adding elements to the document. you will probably find yourself inspecting and editing the source code directly. By the way: most WSDL documents will be generated for you by the SOA Suite design time environment.which protocol and message format . nor does Margaret need that information at this point. note that Frank is at this point far from able to indicate the URL where his service will reside.and the port child of the service element contains the details of the whereabouts of the deployed service implementation.XML Fundamentals </port> </service> August 1. 2010 This element associates a binding element with a physical end point.

Let‟s assume a fairly simple WSDL document along the lines of the PatientDataRecordService . Let‟s see how to read it: <definitions targetNamespace="ourHospital.xmlsoap.but simpler. 2010 The WSDL editor in JDeveloper Demo .PatientData" xmlns:soap12="http://schemas.PatientData" xmlns="" xmlns:xsd="" xmlns:tns="ourHospital. Calling a Web Service is supported by libraries and platform infrastructure in many technology environments. just to give you the idea. you can start writing code to call the web service (even if it does not yet exist).XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B .org/2001/XMLSchema" 15-61 . The WSDL document is shown below.w3.Create the simplest Web Service implementation Once you have the complete WSDL and any referenced XSDs.xmlsoap.

w3. 2010 <schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="" xmlns:hospital="http://ourhospital.Oracle 11g SOA Suite Handbook: Appendix B .com/patient" schemaLocation="SimplePatient.XML Fundamentals xmlns:soap=""/> 8-62 .org/2001/XMLSchema"> <import namespace="" xmlns="" > <types> August 1.xsd"/> </schema> </types> <message name="PatientIdentityRequestMessage"> <part name="in" element="hospital:patientIdentification"/> </message> <message name="PatientDataRecord"> <part name="return" element="hospital:patient"/> </message> <portType name="SimplePatientRecordDataInterface"> <operation name="getPatientDataRecord"> <input message="tns:PatientIdentityRequestMessage"/> <output message="tns:PatientDataRecord"/> </operation> </portType> <binding name="SimplePatientDataRecordServiceSoapHttp" type="tns:SimplePatientRecordDataInterface"> <soap:binding style="document" transport="http://schemas.

XML Fundamentals August 1.w3.xsd document looks like this: <?xml version="1.0" encoding="windows-1252" ?> <xsd:schema xmlns:xsd="http://www. The external" xmlns="http://ourhospital. Through the message elements and the schema referenced from types we quickly get a feel for the input parameters and the outcome of calling the operation. 2010 <operation name="getPatientDataRecord"> <soap:operation soapAction="getPatientData"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="SimplePatientDataRecordService"> <port name="GetPatientDataRecordServiceSoapHttpPort" binding="tns:SimplePatientDataRecordServiceSoapHttp"> <soap:address location="http://host:port/hospital/patientservices/GetPatientDataRecordServiceSoa pHttpPort"/> </port> </service> </definitions> The portType element contains the actual operation on offer in this" 15-63 .Oracle 11g SOA Suite Handbook: Appendix B .

2010 targetNamespace="" elementFormDefault="qualified"> <xsd:element name="patientIdentification" type="patientIdType"/> <xsd:element name="patient" type="patientType"/> <xsd:complexType name="patientIdType"> <xsd:sequence> <xsd:element name="patientId" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="patientType"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="initials" type="xsd:string"/> <xsd:element name="gender" type="genderType"/> <xsd:element name="birthDate" type="xsd:date"/> <xsd:element name="physicalCharacteristic" type="measurementType" minOccurs="0" maxOccurs="unbounded"/> <xsd:element name="hospitalVisit" type="hospitalVisit" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="measurementType"> <xsd:sequence> <xsd:element name="dateOfMeasurement" type="xsd:date"/> <xsd:element name="whatWasMeasured" type="xsd:string"/> <xsd:element name="measuredValue" type="xsd:decimal"/> 8-64 .XML Fundamentals August 1.Oracle 11g SOA Suite Handbook: Appendix B .

2010 <xsd:element name="unitOfMeasurement" type="xsd:string" minOccurs="0"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="hospitalVisit"> <xsd:sequence> <xsd:element name="dateOfVisit" type="xsd:date" maxOccurs="1"/> <xsd:element name="summary" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="genderType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="M"/> <xsd:numeration value="F"/> </xsd:restriction> </xsd:simpleType> </xsd:schema> We can ask for a PatientRecord by submitting the PatientId . The service may return to us an XML document that apparently contains patient details such as name. The endpoint is not yet specified . initials. All you have to add yourself is the Java 15-65 . the service does not even exist at this point. JDeveloper helps us with the implementation of a Web Service: you can ask it to generate a service implementation based on a WSDL document. height. Let‟s first do something about that. In fact. color of eyes. The service is (to be) offered through the SOAP protocol .Oracle 11g SOA Suite Handbook: Appendix B .XML Fundamentals August 1. an integer value. recent hospital visits and some physical characteristics that could include we do not know the actual URL where we can call this service. gender and we can see from the binding element.

@XmlElement(required = true) @XmlSchemaType(name = "date") protected XMLGregorianCalendar birthDate. They provide additional type mapping instructions to the container in which the Web Service will be deployed. The central class generated by the Create Web Service wizard is PatientType . 2010 code that does the actual work. Its properties are defined as follows: public class PatientType { @XmlElement(required = true) protected String name. All the Web Service deployment details and XML to Java data type mapping is taken care of. part of JEE 5. It is now up to us to implement the Class SimplePatientRecordDataInterfaceImpl. The Annotations are part of the JAX-WS specification. Pressing it brings up a wizard that we can by and large accept the default values in. protected List<MeasurementType> physicalCharacteristic.Oracle 11g SOA Suite Handbook: Appendix B .XML Fundamentals August 1. protected List<HospitalVisit> hospitalVisit.based on the XSD Element by the same name. more specifically the method getPatientDataRecord that accepts a PatientIdType and returns a PatientType: 8-66 . @XmlElement(required = true) protected GenderType gender. @XmlElement(required = true) protected String initials. we can find the option Create Web Service in the Right Mouse Menu (RMB) menu. You may want to set a nicer package name in which the Java Classes will be generated. When we select the WSDL file in the Application Navigator.

Web Services once implemented can be called from different technology stacks . download.the main raison d‟être for Web Services. install and run soapUI 2. 2010 public PatientType getPatientDataRecord(PatientIdType in) We can both test and deploy the Web Service from the RMB menu. Tool for (test) invoking and (mock) implementing WebServices: soapUI A useful way. Using soapUI to call Web Services soapUI is an open source tool that frequently comes in handy to quickly try out Web Services and inspect the messages they return. create a new WSDL the URL at which the Web Service is available 5. press the „submit request‟ button. associate the WSDL for the simplePatientDataRecordService with this project 3. edit the end point .Oracle 11g SOA Suite Handbook: Appendix B . once we have implemented this method.soapui. Invoking the Web Service we have introduced above can be done from for example PL/SQL and Java.XML Fundamentals August 1. edit the SOAP request message for the getPatientDataRecord operation (provide an integer value for the patientId) 4. It can be downloaded at http://www. of trying out an existing Web Service as well as providing a quick mock service implementation of a WSDL is through the use of soapUI. perform the following steps: 1. To use soapUI for trying out the simplePatientDataRecordService. to have the service invoked 15-67 .

Oracle 11g SOA Suite Handbook: Appendix B . For service clients who want to start developing and testing before a real service is available. A Web Service call consists of sending a SOAP based XML document across HTTP to the URL specified in the Service element of the WSDL.XML Fundamentals August 1. without writing any implementation code. The PL/SQL code required to invoke the SimplePatientDataRecordService service looks like this: 8-68 . In fact. but it can be called as the real service will be called and it does return values in the appropriate data structure. a mock implementation does not return meaningful values. 2010 Screenshot showing soapUI after making a test call to the simplePatientDataRecordService One of the features offered by soapUI is called MockWebServices. SoapUI can make this service available at a port and URL path you can configure yourself and start receiving SOAP calls. it is very easy to do so. this offers an ideal way of quickly starting out. This allows us to make a Web Service available as described in a WSDL document. Calling a Web Service from PL/SQL A SOAP bound Web Service for which we have the entire WSDL can be called from PL/SQL. PL/SQL can send any text based messages to URLs via HTTP using the UTL_HTTP package and receive synchronous responses as well. Obviously.

org/soap/envelope/"> <soap:Body>**payload**</soap:Body> </soap:Envelope>'. http_resp utl_http. p_target_url in varchar2 in varchar2 .xmlsoap. l_soap_response varchar2(30000). p_soap_action in varchar2 default null ) return xmltype is c_soap_envelope varchar2(250):= '<soap:Envelope xmlns:soap="http://schemas. http_req utl_http.XML Fundamentals August 1. '**payload**'. varchar2(2000).com/patient'. l_target_url '. varchar2(200):= 'http://host:port/hospital/patientservices/GetPatientDataRecordServiceSoapHttpPort function soap_call ( p_payload . begin l_soap_request := replace(c_soap_envelope. l_payload_namespace varchar2(200):= 'http://ourhospital. l_soap_action varchar2(30000):= 'getPatientData'. http_req:= utl_http.begin_request ( p_target_url 15-69 . l_soap_request varchar2(30000).resp.req.Oracle 11g SOA Suite Handbook: Appendix B . p_payload). 2010 DECLARE l_response_payload l_payload XMLType.

write_text(http_req. l_soap_response). August 1. l_response_payload := soap_call(l_payload. 'POST' . -. 'SOAPAction'.1' ). BEGIN l_payload := '<ns1:patientIdentification xmlns:ns1=""' ). END.xmlsoap. 2010 utl_http.XML Fundamentals .tyhat is: the content of the body element in the SOAP envelope return XMLType. utl_http.the actual call to the service is made here http_resp:= utl_http.Oracle 11g SOA Suite Handbook: Appendix B . length(l_soap_request)). 8-70 .createXML( l_soap_response). utl_http. l_target_url.read_text(http_resp. 'text/xml'). end. utl_http.end_response(http_resp). 'HTTP/1. 'Content-Type'. utl_http.set_header(http_req. l_soap_action).com/patient"> <ns1:patientId>43</ns1:patientId> </ns1:patientIdentification>'.set_header(http_req. -. utl_http. l_soap_request). 'Content-Length'. l_soap_action). 'xmlns:soap="http://schemas.extract( '/soap:Envelope/soap:Body/child::node()' .set_header(http_req.only return the payload from the soap response .get_response(http_req).

and will generate the necessary Java classes. 'xmlns="'|| l_payload_namespace||'"'). For example to get hold of the name and birth date of the patient: l_name := l_response_payload.extract('/patient/name/text()'. On top of all generated classes. which must include the proper end point.code to invoke the Web Application that can be integrated with your own application as a piece native Java functionality.xsd document. l_date := to_date(l_response_payload. which is directly based on the patient element in the SimplePatient. 2010 The l_response_payload variable of type XMLType contains the XML message that was returned by the service. 15-71 . The wizard requires the WSDL.getStringVal().getStringVal(). there is the hook we can use to embed the service call in our Java application: public class GetPatientDataRecordServiceSoapHttpPortClient { @WebServiceRef private static SimplePatientDataRecordService simplePatientDataRecordService. 'xmlns="'|| l_payload_namespace||'"'). We can extract structured information from this variable using the operation on the XMLType object. public static void main(String [] args) { simplePatientDataRecordService = new SimplePatientDataRecordService(). it is described by the PatientDataRecord message in the WSDL. it is even easier to create a piece of application logic to call the Web Service.XML Fundamentals August 1. 'YYYY-MM-DD'). Calling a Web Service from Java Using the Web Service facilities in JDeveloper for Java development. The result is based on the JAX-WS specification. JDeveloper can create a so called Web Service Proxy .extract('/patient/birthDate/text()'.Oracle 11g SOA Suite Handbook: Appendix B .

getPatientDataRecord(patientId). 2010 SimplePatientRecordDataInterface simplePatientRecordDataInterface = simplePatientDataRecordService.Oracle 11g SOA Suite Handbook: Appendix B .XML Fundamentals August 1. // Add your code to call the desired methods. patientId. PatientType patient = simplePatientRecordDataInterface. } } 8-72 .getGetPatientDataRecordServiceSoapHttpPort(). PatientIdType patientId = new PatientIdType().setPatientId(new BigInteger("23")).

Sign up to vote on this title
UsefulNot useful