0% found this document useful (0 votes)
2 views

XML

XML (Extensible Markup Language) is a text-based markup language that allows users to create self-descriptive tags for data storage and transfer, developed by the W3C as a public standard. It is widely used for managing large websites, data exchange, and database storage, and can be styled using technologies like XSLT and CSS. XML attributes provide additional information about elements, and references help include special characters to ensure valid syntax.

Uploaded by

Kaustubh Arora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

XML

XML (Extensible Markup Language) is a text-based markup language that allows users to create self-descriptive tags for data storage and transfer, developed by the W3C as a public standard. It is widely used for managing large websites, data exchange, and database storage, and can be styled using technologies like XSLT and CSS. XML attributes provide additional information about elements, and references help include special characters to ensure valid syntax.

Uploaded by

Kaustubh Arora
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

XML

//theory will come


XML stands for Extensible Markup Language. It is a text-based markup
language derived from Standard Generalized Markup Language (SGML).

XML is extensible: XML allows you to create your own self-descriptive tags
or language, that suits your application.

XML carries the data, does not present it: XML allows you to store the data
irrespective of how it will be presented.

XML is a public standard: XML was developed by an organization called


the World Wide Web Consortium (W3C) and is available as an open
standard.

How XML is Used

1. Managing Large Websites – Helps generate HTML pages


dynamically.

2. Data Exchange – Transfers information between different systems.

3. Database Storage – Saves data in a structured format for easy


retrieval.

4. Customization – Lets you organize data as per your needs.

5. Combining with Style Sheets – XML can be styled using CSS or


XSLT to produce readable formats.

6. Universality – Any kind of data (text, numbers, configurations, etc.)


can be represented in XML

7. ML is not a replacement for HTML but complements it.


8. It is flexible, structured, and widely used for data storage and transfer.
9. XML supports various technologies like XSLT, XPath, and XML Schema.
10. It is self-descriptive and helps in data portability and interoperability.

XSLT (Extensible Stylesheet Language Transformations) converts XML data


into HTML.

Code example

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<html>

<body>

<h1>Book List</h1>

<ul>

<xsl:for-each select="library/book">

<li><xsl:value-of select="title"/></li>

</xsl:for-each>

</ul>

</body>

</html>

</xsl:template>

</xsl:stylesheet>
XML Attributes – Explained Simply

XML attributes provide extra details about an element. Instead of


creating multiple elements, we can use attributes to store additional
information.

Example Without Attributes (Repetitive XML)

<plant>

<name>Rose</name>

<type>Flower</type>

</plant>

<plant>

<name>Green</name>

<type>Color</type>

</plant>

Here, we use a separate <type> tag to differentiate plants.

Example With Attributes (Simpler & Clearer)

<plant name="Rose" category="Flower"/>

<plant name="Green" category="Color"/>

 The category attribute tells us whether it’s a flower or a color.

 The name attribute specifies the plant’s name.


Types of XML Attributes

1. StringType (Free text values)

Example:

<book title="XML Guide" author="John Doe"/>

 title and author can contain any text.

2. TokenizedType (With validation rules)

 ID (Unique Identifier)

 <student id="101" name="Alice"/>

 <student id="102" name="Bob"/>

o Each student has a unique id.

 IDREF (Reference to an ID)

 <course code="CSE101" instructor="Dr. Smith"/>

 <enrollment studentID="101" courseCode="CSE101"/>

o The studentID="101" refers to an existing id="101" in the


<student> tag.

3. EnumeratedType (Fixed values only)

Example:

<car brand="Toyota" type="Sedan"/>

<car brand="Honda" type="SUV"/>

 The type attribute can only have values from a predefined list (like
"Sedan", "SUV").

Rules for XML Attributes

1. Attributes must be unique in the same tag ✅

2. <person name="John" age="30"/> <!-- Valid -->

❌ Invalid:

<person name="John" name="Doe"/> <!-- Same attribute repeated -->

3. Attributes should be defined in DTD (if using one)


Example DTD:
4. <!ELEMENT student EMPTY>

5. <!ATTLIST student id ID #REQUIRED>

6. Attributes cannot contain < symbols ❌

7. <message text="5 < 10"/> <!-- Invalid -->

Instead, use:

<message text="5 &lt; 10"/> <!-- Valid -->

When to Use Attributes vs. Elements?

✅ Use attributes for short data like id, category, or type.


✅ Use elements for longer text like descriptions or comments.

Would you like more examples? 🚀

Using XML with JavaScript and AJAX

 JavaScript and AJAX (Asynchronous JavaScript and XML) can fetch


XML data and update HTML dynamically.

 XML can be embedded in an HTML page to structure data. JavaScript


can be used to extract and display XML data.

 It is usually stored in a simple text file and is processed by special


software that is capable of interpreting XML.

 NO RULES(ahead few)

XML components
The diagram illustrates the syntax rules for writing different types of
markup and text in an XML document. It highlights five key
components:

1. XML Declaration – This is the first line in an XML document,


specifying the XML version and encoding.

o Example:

o <?xml version="1.0" encoding="UTF-8"?>

Needed

An HTTP protocol can override the value of encoding that you


put in the XML declaration.
2. Tags & Elements – XML documents consist of elements enclosed in
tags, which define the structure of the data.

o Example:

o <book>

o <title>XML Guide</title>

o </book>

Should work like a stack

Case sensitive

And one root only

//define scope of elemen tin XML

The text that appears between start-tag and end-tag is called


content. An element which has no content is termed as empty. An
empty element can be represented in two ways as follows:

//a complete empty tag

 Tag: A part of an XML element (either opening or closing), used to


define the element boundaries.

 Element: A complete unit that consists of an opening tag,


optional content, and a closing tag.

Attributes – Additional information can be provided within elements


using attributes.

o Example:

o <book category="technology">

o <title>XML Guide</title>
o </book>

o Attribute names are defined without quotation marks, whereas


attribute values must always appear in quotation marks.

o Same attribute cannot have two values in a syntax.

3. Text – The actual content inside XML elements.

o Example:

o <message>Hello, World!</message>

References – XML References Explained

XML references help include special characters and additional text in an XML document.
Since certain characters (like <, >, &) have special meanings in XML, references ensure that
they are correctly interpreted as data rather than code.

There are two types of references in XML:

1. Entity References

 These use a name between & (ampersand) and ; (semicolon).


 They replace reserved characters or include predefined text.
 Example:
 <note>Use &lt;tag&gt; in XML.</note>
Output:

Use <tag> in XML.


Common Entity References:

Entity Meaning
&lt; < (Less than)
&gt; > (Greater than)
&amp; & (Ampersand)
&quot; " (Double quote)
&apos; ' (Single quote)
2. Character References

 These use a numeric Unicode code for a character, starting with &# and ending with
;.
 They are useful for special symbols and characters not present on a keyboard.
 Example:
 <message>Letter A: &#65;</message>

Output:

Letter A: A

More Examples:

Character Unicode Reference Output


A &#65; A
B &#66; B
€ &#8364; €
☺ &#9786; ☺

Use of XML References

1. Prevent Syntax Errors:


o <, > and & are reserved in XML. Using references ensures valid XML.
o Example:
o <text>This is an &lt;XML&gt; example.</text>
2. Include Special Characters:
o Character references help include symbols like ©, €, or non-keyboard
characters.
3. Support Multilingual Text:
o Unicode character references allow the use of various languages in XML.

Conclusion:
XML references make documents readable, structured, and error-free by handling
reserved symbols and special characters effectively.

Note
Whitespace characters like blanks, tabs and line-breaks between XML-elements and between
the XML-attributes will be ignored.

\Using XML with JavaScript and AJAX

 JavaScript and AJAX (Asynchronous JavaScript and XML) can fetch


XML data and update HTML dynamically.

You might also like