Before proceeding further to learn SOA, first we have to see
what are the basic prerequisite technologies to be learned. The list is as
below:
1) XML
2) XML Schema
3) WSDL
4) XPath
5) XSL
Let us start our journey from XML.
XML
----------
- XML stands for eXtensible Markup Language and is mainly designed to transport and store data.
- XML is a markup language much like HTML but XML tags are not predefined and we can define our own tags
- XML is a software- and hardware-independent tool for carrying information
Example XML looks as below:
<?xml version="1.0" encoding="UTF-8"?>
<Letter xmlns=”http://Srini.blogs.com/letter”>
<to>Srini</to>
<from>Vas</from>
<Subject>Hello</Subject>
<body>Hello Everyone !!!</body>
</Letter>
<Letter xmlns=”http://Srini.blogs.com/letter”>
<to>Srini</to>
<from>Vas</from>
<Subject>Hello</Subject>
<body>Hello Everyone !!!</body>
</Letter>
The first line is the XML declaration. It defines the XML
version (1.0) and encoding to be used for understanding data in XML.
The next line is Root element i.e <Letter>
Next 4 lines are the elements inside the root element and so
they are called as child of the root element.
Last line ( </Letter>) defines the end of the root
element.
After looking in to XML we can say it represents a tree
structure which contains parent-child relationship.
Next we will see what are the rules to say an XML is
well-formed. The conditions to be satisfied are :
- All elements must have a closing tag. Eg: <Letter>…….</Letter>
- XML tags are case sensitive. The tag <Letter> is different from the tag <letter>
<Letter><From>abc</Letter></From>
is illegal and
<Letter><From>abc</From></Letter>
is correct since tags are properly nested.
- XML documents must have a root element.
· XML documents must contain one element that is the parent of
all other elements. This element is called
the root element. In our example <Letter> is root element.
- XML attribute values must be quoted
<Letter
lang=eng>…</Letter> is illegal and
<Letter
lang=”eng”>…</Letter> is correct since attribute value is in quotes.
Let us see some more features of XML below:
- Comments in XML should be used as <! -- Comment -- >
- White space values are preserved in XML. <name>Sri Ni</name> is preserved with space
Escape characters in XML:
Since XML elements are represented using ‘<’ and ‘>’ if
the value of certain element contains ‘<’ or ‘>’ in its value then we
need to use escaping to preserve the value correctly.
The below value of body should be as below:
<body> Hello < everyone </body>
‘<’ character in value will be understood as ending tag of
body but it is not the one and so to preserve the value we need to write it as
below:
<body> Hello < everyone </body> so that
‘<’ character in value is understood correctly by parser.
Similar list of escape characters are as below:
<
|
<
|
less than
|
>
|
>
|
greater than
|
&
|
&
|
ampersand
|
'
|
'
|
apostrophe
|
"
|
"
|
quotation mark
|
Naming rules for XML element value:
·
Names can contain letters, numbers, and other
characters. Eg: <bod12y>Srini</ bod12y > is
valid.
·
Names cannot start with a number or punctuation character.
Eg: <1body>Srini</1body> is invalid
·
Names cannot start with the letters xml (or XML, or Xml,
etc) Eg: <xmlbody>Srini</ xmlbody > is invalid.
·
Names cannot contain
spaces. Eg: <na
me>Srini</na me> is invalid
Namespaces:
In sample XML below, we are defining a namespace
xmlns=http://srini.blogs.com/letter
<?xml version="1.0" encoding="UTF-8"?>
<Letter xmlns=”http://Srini.blogs.com/letter”>
<to>Srini</to>
<from>Vas</from>
<Subject>Hello</Subject>
<body>Hello Everyone !!!</body>
</Letter>
<Letter xmlns=”http://Srini.blogs.com/letter”>
<to>Srini</to>
<from>Vas</from>
<Subject>Hello</Subject>
<body>Hello Everyone !!!</body>
</Letter>
This namespace is used to resolve conflicts between same names
in different XML.
Let us take one more example XML which shows the conflict.
<?xml version="1.0" encoding="UTF-8"?>
<Letter xmlns=”http://Srini.blogs.com/letter1”>
<reach>Srini</reach>
<sent>Vas</sent>
<Shortmessage>Hello</Shortmessage>
<message>Hello Everyone !!!</message>
</Letter>
<Letter xmlns=”http://Srini.blogs.com/letter1”>
<reach>Srini</reach>
<sent>Vas</sent>
<Shortmessage>Hello</Shortmessage>
<message>Hello Everyone !!!</message>
</Letter>
If I am using both the above XML in one more XML then I will
have a conflict if namespace http://srini.blogs.com/letter or
http://srini.blogs.com/letter1 are not defined since both are having the same
name Letter and we will get a conflict if I refer Letter to which Letter it
will exactly refer.
No comments:
Post a Comment