Wednesday, 14 August 2013

SIMPLE ELEMENT

An element is called as simple element if it doesn’t contain child element (or) attributes, it should contain only data.
Syntax:
<XS: element name=”XXX” type=”YYYY”/>
/*HERE xxx represents the name if the element and Y represents the datatype of the element */
Example:
<XS: element name=”rollno” type=”XS:integer”/>
Creating a simple element whose value is Fixed
Syntax:
<XS: element name=”xxx” type=”yyyy” fixed=”value”/>
Example:
<XS: element name=”coll code” type=”XS:integer” fixed=”1234”/>
Creating a simple element with a default value:
Syntax:
<XS: element name=”XXX” type=”YYYY” default=”value”/>
Example:

<XS: element name=”fee” type=”XS:integer” default=”30000”/>

COMPLEX ELEMENT

A complex element can be empty, it can contain some child elements and/or attributes.
Syntax:
<xs: element name=”XXX”>
<xs:complex type>
<xs: sequence>
<xs: element name=”x1” type=”y1”/>
<xs: element name=”x2” type=”y2”/>
</xs: sequence>
</xs: complex type>

</xs: element>

XML SCHEMA

XML SCHEMA
(1)    XML schema is an XML based alternative to XML DTD.
(2)    XML  schemas are written in XML
(3)    XML schemas is used to define a structure for the XML Document.
(4)    XML Schema is more powerful and richer in functionality.
(5)    XML schema is a successor to XML DTD
(6)    XML Schema supports name spaces
(7)    XML Schema supports data types

(8)    XML Schema can be used to create our own data types based on the standard datatypes

Tuesday, 13 August 2013

PROCEDURE TO OPEN XML SPY IDE


IDE

It stands for Integrated Development Environment
·         It is used to development application on faster that is reduced the development time and it guides to write the proper syntax.
·          
·         Ex:  
XML, SPY, STYLUS STUDIO


Procedure to open XML SPY IDE:

1.       Click on start->All Programs->Altova XML SPY (Press Enter)
Procedure to create a DTD Document.

1.       Click on File->New->select DTD : Document Type Defn(press enter)
2.       Click on OK button

3.       Opens a DTD Doc

<!ELEMENT institute (student +)>
<!ELEEMENT student(rollno, name,mobileno*, address?)>
<!ELEMENT rollno(#PCDATA)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT mobileno(#PCDATA)>
<!ELEMENT address(hno,colony, city)>
<!ELEMENT hno(#PCDATA)>
<!ELEMENT colony(#PCDATA)>
<!ELEMENT city(#PCDATA)>
<!ATTLIST student course (xml/html/java/.net)”XML”>
<!ATTLIST student CDATA#IMPLIED >
<!ATTLIST address state CDATA #FIXED “AP”>

Save the above document by rules.DTD(any name)

Procedure for creating XML Document

1.       Click ->file ->new->XML Extensible mark up langue
2.       Click on OK
1.       TO create  XML Document containing External DTD Rules then select a DTD, click on OK
2.       Specify the  location of the DTD document and click on OK
3.       XML Document following Externla DTD rules:
<!DOCTYPE institute SYSTEM “D:\rules.dtd”>
<institute>
 <student course=”html” type=”regular”>
 <rollno>100</rollno>
<name>raj</name>
<mobileno>9849186838</mobileno>
<mobileno>961455660</mobileno>
<address state=”AP”>
<hno>420</hno>
<colony>Wilson</colony>
<city>hyd</city>
</address>
</student>

</institute>



·         We can write the DTD rules internal or external Doc but it is always recommended to write External DTD rules

Rules for Creating an XML Document Storing Products information.
1.       Create an element called market as the root tag
2.       Create an element called product under <market> tag which should be present minimum one time.
Create pid, pname, price, describe as child tags to product tag.
3.       The pid and pname must be present exactly one time.
4.       The price element must be available one (or) more time
5.       The desc element can be present 0(zero) or 1 time
6.       Create an attribute called qualities under product tag which is mandatory
7.       Create an attribute called barcode under product which is optional
<!ELEMENT Market (product +)>
<!ELEMENT product (pid, pname,price+,desc?)>
<!ELEMENT pid(#PCDATA)>
<!ELEMENT PNAME(#PCDATA)>
<!ELEMENT PRICE(#PCDATA)>
<!ELEMENT desc (#PCDATA)>
<!ELEMENT product quantity CDATA #REQUIRED>
<!ATTLIST product quantity CDATA #REQUIRED>
<!ATTLIST product barcode CDATA #IMPLIED>

PROCEDURE TO OPEN XML SPY IDE

XML Parser

To validate an XML Doc we require XML Parser.
·         XML Parser is an utility tool using which we can check whether or XML Document is well formed or not, valid or not>
Examples of XML Parser:
1.       SAX(Simple API for XML Processing)
2.       DOM(Document Object Model)
3.       JDOM(Java document Object Model)
4.       Dom4J(Document Object Model for Java)
Note: the XML Parser can even used for processing the XML Document
1.       What is an XML Parsers? What are its functions?
·         XML parser is an API that enables XML applications to work with XML document.
·         An XML parser performs the following things: (1) reading the xml docu (2) checking well-formedness (3) verify its validity (4) making XML data available to XML application.


1.       Xml application instantiating the parser and specifying the xml file to the parse(i.e passing the name of the XML file name to the parser)
2.       Parser reads the specified xml document and verifies its well formedness.
3.       In the xml document parser gets the information about the DTD or XSD. Parser verifies the correctness of the DTD or XSD.
4.       Parser reads the metadata specified in the DTD or XSD file into the memory.
5.       Basing on the metadata read into memory; XML parser verifies the validity of the XML document.
6.       Parser makes XML content (data) available to the XML  application either in the form of a tree structure or in the form or events
Valid XML Document:
·         XML parser can make data stored in XML document available to XML application if and only if the XML documents are valid.
·         There are two approached for developing valid XML. (I) using DTD (ii) using XSD
What is DTD?
·         DTD stands for document type definition
·         A DTD is a text file with .dtd extension
·         If XML file holds data, its corresponding DTD holds Meta data.
In a DTD legal building blocks of an XML documents are specified. i.e XML vocabulary is specified in A dtd.
What are the constituents of DTD file?
·         DTD point of view, all XML DOCUMENTs are made up by the following building blocks:
1.       Elements
2.       Attributes
3.       Entities
4.       PCDATA
5.       CDATA
ELEMENTS:
ATTRIBUTES
ENTITIES:
Some of the characters have a special meaning in XML , like the less than sign(<) that defines the start of a XML tag . most of you know the HTML Entity:”&nbsp;” this “no-breaking-space” entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser.
The following entities are predefined in XML:
ENTITIY REFERENCE
CHARACTER
&lt;
< 
&gt
> 
&amp
&
&quot
“
&apos;
‘

PCDATA:
Xml parsers normally parse all the text in an XML document. When an XML element is parsed, the text between the xml tags is also parsed:
Ex: <message>This text is also parsed<message>
The parser does this because XML elements can contain other element, as in this example, where the <name> element contains two other elements(first and last):
<name><first>Bill</first><last>Gates</last></name>
And the parser will break it up into sub-elements like this:
<name>
 <first>Bill</first>
<last>Gates</last>
</name>
Parsed Character Data (PCDATA) is a term used about text data that will be parsed by the XML parser.

CDATA-(Unparsed) Character Data
·         The term CDATA is used about text data that should not be parsed by the XML parser.
·         Characters like “<” and “&” are illegal in XML elements.
·         “<” will generate an error because the parser interprets it as the start of a new element
·         “&” will generate an error because the parser interprets it as the start of an character entity.
·         Some text , like JAVASCRIPT code, contains a lot of “<” or “&” characters. To avoid errors script code can be defined as CDATA.
·         Everything inside a CDATA section is ignored by the parser.
C DATA section starts with “<![CDATA[“and ends with “]]>”:
<script>
<![CDATA[function matchwo(a,b)
{
if(a<b&&a<0) then
{
 return l;
}
else
{
return 0;
}
]>
</script>
·         In the example above, everything inside the CDATA section is ignored by the parser.
Note: CDATA Sections: can not contain the string “]]>”. Nested CDATA sections are not allowed.
The “]]>” that marks the end of the CDATA section can not contain spaces or line breaks.

·         In the examples are declared with an element declaration. An element declaration has the following syntax:

Entity



This building block is used to create special characters by using ENTITY declaration
a.       Declare an internal entity
Syntax: <!ENTITY entity_name entity_value>
Example:
b.      Declare an external entity
Syntax: <!ENTITY entity_name system URL>



Element
Attributes:
Rules to be Prepared For an XML Document Storing Student Information