EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials XML Tutorial XML Special Characters
Secondary Sidebar
XML Tutorial
  • Basic
    • What is XML?
    • XML Tags
    • XML URL
    • XPath Sibling
    • XML root element
    • XML Encryption
    • XML Parsing php
    • xml parsing with java
    • Dataset XML
    • XML Parser in C#
    • XML Tree
    • XML boolean
    • XML sitemap
    • XML Array
    • XML reserved characters
    • XML Viewer
    • XML Uses
    • XML Special Characters
    • XML generator
    • XML file format
    • XML DOM
    • XML ampersand
    • XML Mapping
    • XML File
    • XML Element
    • XML HttpRequest
    • XML XSD
    • XML Schema
    • XML Namespaces
    • XML Comments
    • XML Attributes
    • XML Encoding
    • XML Validation
    • XML CDATA
    • XML Database
    • XML Technologies
    • XML Error
    • XML DTD
    • XML Date
    • XML Parsers
    • String in XML
    • XML with CSS
    • XML Versions
    • XML Features
    • XML Commands
    • Servlet web.xml
    • XPath Injection
    • XPath Functions
    • XPath starts-with
    • XPath Selector
    • XPath Count
    • XPath XML
    • XML Parsing in Oracle
    • XML parsing in python
  • Xpath
    • What is XPath?
    • XPath namespace
    • XPath for JSON
    • XPath Last Element
    • Xpath Substring
    • XPath First Element
    • XPath local-name
    • XPath Multiple Attributes
    • XPath Matches
    • XPath Position
    • XPath Index
    • XPath regex
    • XPath id contains
    • XPath innertext
    • XPath Multiple Conditions
    • XPath Helper
    • XPath Generator
    • XPath ID
    • XPath Locator
  • Xquery
    • What is Xquery

XML Special Characters

XML Special Characters

Definition of XML Special Characters

Special Characters, also named a non-Latin character in XML, are assigned inside the XML file with the numeric Character reference by replacing entities. These characters are appeared in the escaped format using entity formation. The special Characters <, > are converted into escaped equivalent like &lt and &gt. Few developers find it difficult to use XML special characters; let’s say, when embedding a few texts inside a document with an ampersand, the parser couldn’t process the document. So, under CDATA sections, a Special Characters encoding should use XmlFormat () while this function handles Special characters for effective changes.

Syntax

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

There is no Specific Syntax to declare. It could be assigned in an attribute or an element like:

<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance”>
<Latinchar>͍ </ Latinchar >
</Report>

XML special characters with an example

Certain Characters are treated special when progressing XML Document, and these are used as Mark-up Syntax should be escaped approximately. These characters cannot be inserted directly as an attempt to the XML file so that there need to be a character reference or a numeric reference to preserve across the working platforms.

&lt Left bracket
&gt Right Bracket
&amp Ampersand symbol
&quot Double Quotes
&apos Single Quotes

For instance, a file containing XML has

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<item_list>
Product size &gt; applied
</item_list>

Now the result of Processing the above sample is given as

Element: <item_list>
Char: Product size > applied
End element: </item_list>

When an XML file is big, including Special Characters in such a case, we can use the CDATA section to handle it. Another section of XML is Xpath which uses Special Characters in their Path Language.

 . Here the current context should be Specified in the node.
* This character is named a wild Character use to select all the elements.
@  Specifically selects an attribute.
() In an Xpath expression, this specifies a grouping.
 :  This is a Namespace Separator

These could be used in a variety of ways, and it is a good start to learn how to use these into numeric formats in a variety of applications and in XML.

In the following section, let’s see how to use special entities in language with XML construction. Let’s get started here.

Example #1 – Using Cdata

res.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Special Characters in Math Expressions functions. </title>
</head>
<body>
<h1><b> This example Shows how to use Special characters in a expression or paragraph using XML </b></h1>
<div id ="demo1">
<! [CDATA[
Lets take an expression of a formula " if Q(a,c) is a c < Q && a > A or c > a "
]]>
</div>
</body>
</html>

Output:

XML Special Characters Example 1

Example #2 – Using apos and &lt

Let’s talk about character data in the XML document, and here ‘&’ and “< “should not be used in the mark-up, but apos and quotes could be appearing directly without encoding. For instance, code like

<?XML version="1.0”?>
<password > “ ‘ > </password>

The above sample code is valid; therefore, the XML parser parses and validates the result as

Output:

XML Special Characters Example 2

Example #3 – Using Complete Special Characters

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book ISBN="586954">
<title>&quot;Java Advanced &quot;</title>
<author>Emey mark</author>
<category>Programming & Analysis</category>
<edition>1</edition>
<price> &lt;29.99 &gt;</price>
</book>
<book ISBN="56858">
<title>&quot;More for Python &quot;</title>
<author>&amp;Hebrew manni</author>
<category>Programming</category>
<price>15.99</price>
</book>
<book ISBN="66547">
<title>&quot;The Complete Guide to Animals &quot;</title>
<author>joe emacul</author>
<author>sheeba david</author>
<author>Jacob ethen</author>
<category>Wild</category>
<category>Teresstial</category>
<language>French</language>
<edition>5</edition>
<price>31.99</price>
</book>
</bookstore>

Explanation 

In the above code, an XML element is assigned with the special character tags.

Output:

XML Special Characters Example 3

Example #4 – Using the ampersand

<?xml version="1.0" encoding="UTF-8"?>
<password > & </password>
<Login> &@</Login>

Output:

XML Special Characters Example 4

Example #5 – With ampersand and Numeric

<?xml version="1.0" encoding="utf-8"?>
<Result>
<College noOfWorkers="-4120">
<Principal>
<LName>&amp;DivyaSri</LName>
<Idno>124</Idno>
</Principal>
<Faculty>
<FName>&Anish</FName>
<LName>Ram</LName>
<FfName>nagesh</FfName>
<Idno>1235</Idno>
</Faculty>
<Dept>string</Dept>
</College>
</Result>

Explanation

In the above code, the Fname element is declared with a special character, and their presence is reflected in the output as shown below:

Output:

XML Special Characters Example 5

Example #6 – Using &gt with CDATA structure

<?xml version="1.0" encoding="UTF-8"?>
<return_val>]]&gt;</return_val>

Output:

Using &gt with CDATA

Example #7 – Using wildcard characters in xml

ord.xsl

<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:template match = "/">
<html>
<body>
<h2> <center>Restaurant-Online </center></h2>
<xsl:apply-templates select = "Ordering/*" />
</body>
</html>
</xsl:template>
<xsl:template match = "Ordering/*">
<xsl:apply-templates select = "@login" />
<xsl:apply-templates select = "Ordering Menu" />
<xsl:apply-templates select = "Food Pricing" />
<xsl:apply-templates select = "Services" />
<xsl:apply-templates select = "Duration delivery" />
<br />
</xsl:template>
<xsl:template match = "@login">
<span style = "font-size = 22px;">
<xsl:value-of select = "." />
</span>
<br />
</xsl:template>
<xsl:template match = "Ordering Menu">
Lang:<span style = "color:blue;">
<xsl:value-of select = "." />
</span>
<br />
</xsl:template>
<xsl:template match = "Food Pricing">
Tutor:<span style = "color:orange;">
<xsl:value-of select = "." />
</span>
<br />
</xsl:template>
<xsl:template match = "Service">
Experience:<span style = "color:green;">
<xsl:value-of select = "." />
</span>
<br />
</xsl:template>
<xsl:template match = "Duration delivery">
Duration:<span style = "color:red;">
<xsl:value-of select = "." />
</span>
<br />
</xsl:template>
</xsl:stylesheet>

ord.xml

<?xml version="1.0" encoding="UTF-8"?>
<Ordering>
<order>
<OrderingMenu>Pizza</OrderingMenu>
<DurationDelivery>15minutes</DurationDelivery>
<FoodPricing>fiftypound</FoodPricing>
<Services>24hours</Services>
</order>
<order>
<OrderingMenu>Burger</OrderingMenu>
<DurationDelivery>10minutes</DurationDelivery>
<FoodPricing>20pounds</FoodPricing>
<Services>12hours</Services>
</order>
<order>
<OrderingMenu>Pizzacheese</OrderingMenu>
<DurationDelivery>20minutes</DurationDelivery>
<FoodPricing>25Pounds</FoodPricing>
<Services>10hours</Services>
</order>
</Ordering>

Explanation

In the above code, the root node is selected by the wildcard (*), in which the child elements and the attribute are selected.

Output:

Using wildcard

Explanation

In the above wildcard example, we have used an XML document with XSL, and a particular value and attributes are selected.

Conclusion

This article demonstrates how to use these Special Characters in XML in various Circumstances. In the case of Xpath, the result produced by the expression is in the form of Node-set. The overall concept is while using Special Characters in XML file; care should be done on the side of the Client as we need to escape a Character. Also, we have gone through a detailed description with examples of these special characters.

Recommended Articles

This is a guide to the XML Special Characters. Here we discuss how to use XML Special Characters along with the examples and outputs. You may also have a look at the following articles to learn more –

  1. XML HttpRequest 
  2. XML Element
  3. XML Schema
  4. XML Attributes
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more