0% found this document useful (0 votes)
59 views13 pages

Q) What Is An XML and Why It Was Designed ? A)

XML was designed to carry and structure data separately from presentation. It allows data to be exchanged between different applications in a standardized, platform-independent way. Key benefits of XML include being a standard, being portable, being extensible through user-defined tags, separating content from presentation, and including metadata to provide context about the data's meaning. XML documents must follow syntax rules like being well-formed through proper nesting and inclusion of closing tags. To be valid, an XML document must also conform to the rules of a DTD or schema that defines its allowed elements and structure.

Uploaded by

Moises Mason
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views13 pages

Q) What Is An XML and Why It Was Designed ? A)

XML was designed to carry and structure data separately from presentation. It allows data to be exchanged between different applications in a standardized, platform-independent way. Key benefits of XML include being a standard, being portable, being extensible through user-defined tags, separating content from presentation, and including metadata to provide context about the data's meaning. XML documents must follow syntax rules like being well-formed through proper nesting and inclusion of closing tags. To be valid, an XML document must also conform to the rules of a DTD or schema that defines its allowed elements and structure.

Uploaded by

Moises Mason
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Q) What is an XML and Why it was designed ? A) XML stands for Extensible Markup Language.

Practically speaking, XML is a method to structure electronic documents, and its aim is to separate presentation, structure, and meaning from the actual content

What is XML?

XML XML XML XML XML stands for EXtensible Markup Language is a markup language much like HTML was designed to carry data, not to display data tags are not predefined. You must define your own tags is designed to be self-descriptive

Q)Why one should needs to use xml ?

XML can be used to describe and identify information accurately and unambiguously, in a way that computers can be programmed to understand your information (well, at least manipulate as if they could understand it). XML allows documents which are all the same type to be created and handled consistently and without structural errors, because it provides a standardised way of describing, controlling, or allowing/disallowing particular types of document structure. [Note that this has absolutely nothing whatever to do with formatting, appearance, or the actual text or data content of your documents, only the structure of them. If you want styling or formatting, see question 5 in the Users section, How do I control formatting and appearance?.] XML provides a robust and durable format for information storage and transmission. Robust because it is based on a proven standard, and can thus be tested and verified; durable (persistent) because it uses plain-text file formats which will outlast proprietary binary ones. XML provides a common syntax for messaging systems for the exchange of information between applications. Previously, each messaging system had its own format and all were different, which made inter-system messaging unnecessarily messy, complex, and expensive. If everyone uses the same syntax it makes writing these systems much faster and more reliable. XML is free. Not just free of charge (free as in beer) but free of legal encumbrances (free as in speech). It doesn't belong to anyone, so it can't be hijacked or pirated. And you don't have to pay a fee to use it (you can of course choose to use commercial software to deal with it, for lots of good reasons, but you don't pay for XML itself).

XML information can be manipulated programmatically (under machine control), so XML documents can be pieced together from disparate sources, or taken apart and re-used in different ways. They can be converted into any other format with no loss of information. XML lets you separate form (appearance) from content. Your XML file contains your document information (text, data) and identifies its structure: your formatting and other processing needs are identified separately in a stylesheet or processing system. The two are combined at output time to apply the required formatting to the text or data identified by its structure (location, position, rank, order, or whatever).

Q) Why an XML is used in the applications ? A)


SELF-DESCRIBING DATA - THE KEY TO SUCCESS Unlike records in traditional data base systems, XML data does not require relational schemata, file description tables, external data type definitions, etc., because the data itself contains this information. MODIFICATIONS TO DATA PRESENTATION - NO REPROGRAMMING REQUIRED You can change the look and feel of documents or even entire websites with XSL Style Sheets without manipulating the data itself. OPEN AND EXTENSIBLE INTERNATIONALIZATION Internationalization is of utmost importance for electronic business applications. XML supports multilingual documents and the Unicode standard.

Q) Why XML is SO important ? A) Because of following reasons XML is so important.

XML is a standard: Each and every XML must conform to a specification defined by the World Wide Web Consortium (W3C) at http://www.w3.org/.This means that XML is a standard. When you send XML, it conforms to this standard; when some other application receives it, the XML still conforms to that standard. Note: Standarad meands Just like ISO , inorder to get an ISO to your product ;you must and should maintain some standards(rules and regulations) specified by ISO. XML is portable : Because XML is simply text, it can obviously be moved between various platforms. Portable means , developing the application in one environment (ex windows) , and deploy those application in some other environments like (UNIX , Solaris,etc). Java is perfect example to portable , due to this reason it became so popular.

XML is platform-independent : The platform-independent nature of XML makes it an ideal format for exchanging structured textual information among disparate applications. Interoperability :
Interoperability is the ability of diverse systems and organizations to work together (inter-operate).

XML's extensibility makes it perfect for cross-application operation. Ex: We can work with xml in the combination of javascript,html, java ,etc.
Q) Benfits of an XML ?
Simplicity :Information coded in XML is easy to read and understand, plus it can be processed easily by computers. Openness : XML is a W3C standard, endorsed by software industry market leaders. Extensibility : There is no fixed set of tags. New tags can be created as they are needed. Self-description : In traditional databases, data records require schemas set up by the database administrator. XML documents can be stored without such definitions, because they contain meta data in the form of tags and attributes. XML provides a basis for author identification and versioning at the element level. Any XML tag can possess an unlimited number of attributes such as author or version. Contains machine-readable context information Tags, attributes and element structure provide context information that can be used to interpret the meaning of content, opening up new possibilities for highly efficient search engines, intelligent data mining, agents, etc. This is a major advantage over HTML or plain text, where context information is difficult or impossible to evaluate. Separates content from presentation XML tags describe meaning not presentation. The motto of HTML is: "I know how it looks", whereas the motto of XML is: "I know what it means, and you tell me how it should look." The look and feel of an XML document can be controlled by XSL style sheets, allowing the look of a document (or of a complete Web site) to be changed without touching the content of the document. Multiple views or presentations of the same content are easily rendered.

XML is reliable :
able to be trusted; predictable or dependable

Q)What are differences between HTML and XML ? A) HTML is an abbreviation for Hyper Text Markup Language while XML stands for extensible Markup Language.The differences are as follows:1.HTML was designed to display data with focus on how data looks while XML was designed to be a software and hardware independent tool used to transport and store data, with focus on what data is. 2.HTML is a markup language itself while XML provides a framework for defining markup languages.

3.HTML is a presentation language while XML is neither a programming language nor a presentation language. 4.HTML is case insensitive while XML is case sensitive. 5.HTML is used for designing a web-page to be rendered on the client side while XML is used basically to transport data between the application and the database. 6.HTML has it own predefined tags while what makes XML flexible is that custom tags can be defined and the tags are invented by the author of the XML document. 7.HTML is not strict if the user does not use the closing tags but XML makes it mandatory for the user the close each tag that has been used. 8.HTML does not preserve white space while XML does. 9.HTML is about displaying data,hence static but XML is about carrying information,hence dynamic.

Q)XML Syntax rules ?


1. All XML Elements Must Have a Closing Tag 2. XML Tags are Case Sensitive 3. XML Elements Must be Properly Nested 4. XML Documents Must Have a Root Element 5. XML Attribute Values Must be Quoted (better give double quotes) 6. Entity References Some characters have a special meaning in XML.If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. This will generate an XML error:
<message>if salary < 1000 then</message>

There are 5 predefined entity references in XML: &lt; &gt; &amp; &apos; &quot; < > & ' " less than greater than ampersand apostrophe quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.

7. Comments in XML The syntax for writing comments in XML is similar to that of HTML.
<!-- This is a comment -->

8)White-space is Preserved in XML

Q) What is meant by well formed xml ? A) Formally, it means that the document must follow the syntax rules specified for XML by the W3C
in the XML 1.0 recommendation or the XML 1.1 candidate recommendation. Although there are a fair number of requirements for a document to be well-formed, informally, the main requirements are that the document must contain one or more elements, and one element, the root element, must contain all the other elements. In addition, each element must nest inside any enclosing elements properly. Q)Valid XML means ? A) A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document
Type Definition (DTD) , XML Schema or other type of schema , which defines the legal elements of an XML document.

DTD :
A Document Type Definition (DTD) defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes.

Internal DTD Declaration


If the DTD is declared inside the XML file, it should be wrapped in a DOCTYPE definition with the following syntax:

<!DOCTYPE root-element [element-declarations]> EX: <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading>

<body>Don't forget me this weekend</body> </note>

External DTD Declaration


If the DTD is declared in an external file, it should be wrapped in a DOCTYPE definition with the following syntax:

<!DOCTYPE root-element SYSTEM "filename"> EX: <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>

Note.dtd:
<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> DTD Buildng blocks: PCDATA PCDATA means parsed character data.
Think of character data as the text found between the start tag and the end tag of an XML element.PCDATA is text that WILL be parsed by a parser. The text will be examined by the parser for entities and markup.Tags inside the text will be treated as markup and entities will be expanded.

CDATA : CDATA means character data.


CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.

Elements with Parsed Character Data


<!ELEMENT element-name (#PCDATA)>

Elements with any Contents


Elements declared with the category keyword ANY, can contain any combination of parsable data:

<!ELEMENT element-name ANY>

Elements with Children (sequences)


Elements with one or more children are declared with the name of the children elements inside parentheses:

<!ELEMENT note (to,from,heading,body)>

Declaring Only One Occurrence of an Element


<!ELEMENT note (message)>
The example above declares that the child element "message" must occur once, and only once inside the "note" element.

Note : + indicates that 1 or more * indicates that 0 or more ? indicates that 0 or 1

| for declaring content as either or cases

Declaring either/or Content


<!ELEMENT note (to,from,header,(message|body))>
The example above declares that the "note" element must contain a "to" element, a "from" element, a "header" element, and either a "message" or a "body" element.

Declaring Mixed Content


<!ELEMENT note (#PCDATA|to|from|header|message)*>
The example above declares that the "note" element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements.

Empty elements : Empty elements are declared with the keyword EMPTY inside the parentheses:
<!ELEMENT element-name (EMPTY)> example: <!ELEMENT img (EMPTY)>

DTD Attributes
In a DTD, attributes are declared with an ATTLIST declaration.
<!ATTLIST element-name attribute-name attribute-type default-value> DTD example: <!ATTLIST payment type CDATA "check">

XML example: <payment type="check" />


The attribute-type can be one of the following: Type CDATA (en1|en2|..) ID IDREF IDREFS NMTOKEN NMTOKENS ENTITY ENTITIES NOTATION xml: Description The value is character data The value must be one from an enumerated list The value is a unique id The value is the id of another element The value is a list of other ids The value is a valid XML name The value is a list of valid XML names The value is an entity The value is a list of entities The value is a name of a notation The value is a predefined xml value

The default-value can be one of the following: Value value #REQUIRED #IMPLIED #FIXED value Explanation The default value of the attribute The attribute is required The attribute is not required The attribute value is fixed

#REQUIRED :

Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present.

Syn :<!ATTLIST element-name attribute-name attribute-type #REQUIRED> DTD: <!ATTLIST person number CDATA #REQUIRED> Valid XML:<person number="5677" /> Invalid XML: <person />

#IMPLIED :

Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value.

Enumerated Attribute Values :

Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values.

Syntax : <!ATTLIST element-name attribute-name (en1|en2|..) default-value>


DTD: <!ATTLIST payment type (check|cash) "cash"> XML example: <payment type="check" /> or <payment type="cash" />

Ex: The XML Document


<?xml version="1.0" standalone="yes"?> <family> <title>My Family</title> <parent role="mother">Judy</parent> <parent role="father">Layard</parent> <child role="daughter">Jennifer</child> <image source="JENN" /> <child role="son">Brendan</child> &footer; </family> The DTD <!DOCTYPE family [ <!ELEMENT title (#PCDATA)> <!ELEMENT parent (#PCDATA)> <!ATTLIST parent role (mother | father) #required> <!ELEMENT child (#PCDATA)> <!ATTLIST child role (daughter | son) #required> <!NOTATION gif system "image/gif">

<!ENTITY JENN system "http://images.about.com/sites/guidepics/html.gif" NDATA gif> <!ELEMENT image empty> <!ATTLIST image source entity #required> <!ENTITY footer "Brought to you by Jennifer Kyrnin"> ]>

XML Namespaces: XML Namespaces provide a method to avoid element name conflicts.
XML namespaces are a way to avoid conflicts between element names when two (or more) different specifications are in use. For example, if you were a furniture store, you might have an XML driven website that had your entire catalog in XML and you want to display it in XHTML on the Web. For your document you might have an XHTML table like this:

A namespace is a set of names in which all names are unique Declaring a name space <root Xmlns:namespacename=uri> Here xmlns means xml namespace and uri is uniform resource locator. Ex: <root xmlns:myname=http://www.mynamespce.com/myxml/> When you define your namespaces, the URIs do not have to actually be resolvable. In other
words, they may not go to anything at all. <table> <tr> <td>Oak</td> <td>6'x4'</td> <td>$300</td> </tr> </table> And your catalog might have a table like this: <table> <wood>oak</wood> <length>6'</length> <width>4'</length> <price>$300</price> </table>

EX: <?xml version="1.0" ?> <root xmlns:html="http://www.w3.org/HTML/1998/html4" xmlns:furniture="http://webdesign.about.com/furniture"> <html:table> <html:tr> <html:td>Oak</html:td> <html:td>6x4</html:td> <html:td>$300</html:td> </html:tr> </html:table> <furniture:table> <furniture:wood>oak</furniture:wood> <furniture:length>6'</furniture:length> <furniture:width>4'</furniture:width> <furniture:price>$300</furniture:price> </furniture:table> </root>

NOTE: name spaces are just similar to java packages.

XML Schema : Q)

What is an XML Schema? -- it is a blue print of xml

The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema:

defines elements that can appear in a document defines attributes that can appear in a document

defines defines defines defines defines defines

which elements are child elements the order of child elements the number of child elements whether an element is empty or can include text data types for elements and attributes default and fixed values for elements and attributes

Q)Differences between xml schema and DTD ?

1) XML schemas are written in XML while DTD are derived from SGML syntax. No need to learn new syntax and language. 2) XML schemas defines datatypes for elements and attributes while DTD doesn't support datatypes. 3) XML schemas allows support for namespaces while DTD doesn't support. It resolves name conflicts. 4) XML schemas defines no. and order of child elements while DTD doesn't defines. 5) XML schemas can be manipulated own your own with XML DOM but it is not possible in case of DTD. 6) using XML schema user need not to learn a new language but working with DTD its difficult for a user. 7) XML schema provides secure data communication i.e sender can describe the data in away that receiver will understood but in case of DTD data can be misunderstood by the receiver. 8) XML schemas are extensible while DTD is not extensible.

Q) Why use XML Schema for data? Strong typing for elements and attributes Standardized way to represent null values for elements Key mechanism that is directly analogous to relational database foreign keys Defined as XML documents, making them programmatically accessible

SAX , DOM,JDOM ; All these 3 are different APIs for accessing XML Document .All three offer you to access to an XML document, in differing forms, and let you do pretty much anything you want with the document.

XML Parser : One of the most important layers to any XML-aware application is the XML parser. This component handles the important task of taking a raw XML document as input and making sense of the document; it will ensure that the document is well-formed, and if a DTD or schema is referenced, it may be able to ensure that the document is valid. What results from an XML document being parsed is typically a data structure that can be manipulated and handled by other XML tools or Java APIs.

Based on following criteria and based on your application needs you can select suitable parser. The first is the speed of the parser. As XML documents are used more often and their complexity grows, the speed of an XML parser becomes extremely important to the overall performance of an application. The second factor is conformity to the XML specification.
Ex: Bleow are some few parsers.
Apache Xerces: http://xml.apache.org/ (It is most popular , because it is open source) IBM XML4J: http://alphaworks.ibm.com/tech/xml4j James Clark's XP: http://www.jclark.com/xml/xp Oracle XML Parser: http://technet.oracle.com/tech/xml

Note: In addition, most XML parsers are validating,which means they offer the option to validate

your XML with a DTD or XML Schema, but some are not. Make sure you use a validating parser if that capability is needed in your applications.

FAQS: Q) What is xml interoperability ? A) XML Interoperability: the ability of an application to make effective
use of an XML document that it receives. There are two ends of the XML Interoperability spectrum: [1] At one end of the spectrum an application is coded for a specific schema and this is able to make effective use of only XML documents that conform to that schema. [2] At the other end of the spectrum the application is able to make effective use of any XML document that it receives, regardless of the schema that the XML document conforms to. I contend that [2] is the desired goal, but [1] is where we are at currently. So, how do we get to [2]? That's what I wish to explore.

You might also like