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 File 
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

XML File 

By Priya PedamkarPriya Pedamkar

XML File 

Definition of XML File

An Extensible Mark Up file is defined as a text-based language that carries data in the form of tags not the format of the data. It is the most efficient way to store and move data online. XML file holds XML code and the file is saved under the extension .xml. It is formatted with tags like HTML tags and other XML-based file types include EDS, FDX, and DAE files. An XML file acts as a database to store the data. The most commonly used example of an XML-based file is RSS Feed.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,198 ratings)

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

A very Simple Syntax is given as

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<child>
</child>
</root>

How does File work in XML?

In this article, let’s see how to construct a simple XML file on our own. The XML file is plain text to store or transfer data on the internet. Web-based applications store information and transfer it through the web in XML format. Though XML file is meant for storages the format of them is very important. For example, XML format is used for musical files.

The file works well in all editors to view an XML file or to change the formats it is recommended to use XML viewers Online. In the case of Text editors, an XML file is opened as a text file. Commonly used text editors are Notepad and WordPad to read an XML file. Well, known popular Online viewers are Code Beautify and JSON Formatter. The main reason for accessing XML files is good for data Storage. The hierarchical format of XML file includes:

  • Child Element: The element inside another element.
  • Global Element: Direct child element of the root tag. This Global element is referenced ain XML Schema.
  • Local Element: It is a nesting element.

Other elements are multiple-occurring and single occurring elements.

These XML files could work on R programming and Java Programming provided the packages have to be installed.

Creating a File:

It is done by practicing our XML files in a text editor.

  1. Open the text-editor file.
  2. And the first line of the file should include an XML declaration to tell the editor that it is an XML file.
  3. The next step is to create a root element which is the main role in the XML file. The root element should start with the start tag and end with the close tag.
  4. Followed by this is adding a child element.

The XML file is created by storing the information of a particular project in tags and save the file using the file extension ‘.xml’. Let’s see the sample XML file to do the operations:

demo.xml

<shops>
<Type>
<No>1</No>
<NAME> riyaz</NAME>
<Street>620</Street>
<City>Bangalore</City>
</Type>
</shops>

Reading the XML file in R:

data <- xmlParse(file = "demo.xml")
print(data)

To check how XML file is loaded into Caching Database we need the following attributes namely:

  • FileName: Entering the full file Path to load it into the page.
  • JPath/ Xpath: Defining the XML file to locate without Namespaces.

Few converters convert the XML file to other formats like HTML, CSS, and XSD.

Using a Text editor

As XML file is a text file, we can open it in any editors which helps to open and display the XML file Contents. In different programs we can open an XML file. Formally, right-click the XML file -> open-> Menu -> choose any programs to open.

XML File -1.1

Using a Web browser to see the data in a File

To view the XML file in a Browser it shows as a Document tree. The sample is shown below in which it displays in a different color. Although we can see in blue text, still they are unclickable. To know exactly what these XML tags are been, it is recommended to use XSLT  to transform XML into various output formats.

XML File -1.2

Examples of XML File

This section covers how to create an XML file and letting them to execute in a Web browser.

Example #1

small.xml

<?xml version="1.0”?>
<Folders>
<Folder>
<StdName>Joe Biden</StdName>
<Specialization>ICSE</Specialization>
<Position>Senior</Position>
<G1>82</G1>
<G2>96</G2>
<G3>96.2</G3>
<tut1>94.4</tut1>
<G4>0</G4>
<G5>95.2</G5>
<tut2>99.2</tut2>
</Folder>
<Folder>
<StdName>Kamala Harish</StdName>
<Specialization>BQE</Specialization>
<Position>Low-level</Position>
<G1>84</G1>
<G2>95</G2>
<G3>95.2</G3>
<tut1>93.4</tut1>
<G4>10</G4>
<G5>95.1</G5>
</Folder>
<Folder>
<StdName>Lawrence mark</StdName>
<Specialization>CBSE</Specialization>
<Position>Junior</Position>
<G1>72</G1>
<G2>94</G2>
<G3>95.2</G3>
<tut1>93.4</tut1>
<G4>0</G4>
<G5>93.2</G5>
</Folder>
</Folders>

Explanation: This is how we created a file to work with which is a completed version XML file. Folders is a root element and it contains sub-elements stdname, specialization. The folder is a parent element, stdname, specialization, G1..G5 are sibling elements. The following output shows the elements, structures, and attributes in an XML file.

Output:

 XML File -1.3

Example #2 – Using DOCTYPE

book.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore [
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author+, category*, language?, year?, edition?, price)>
<!ATTLIST book ISBN CDATA #REQUIRED>
<!ELEMENT title    (#PCDATA)>
<!ELEMENT author   (#PCDATA)>
<!ELEMENT category (#PCDATA)>
<!ELEMENT language (#PCDATA)>
<!ELEMENT year     (#PCDATA)>
<!ELEMENT edition  (#PCDATA)>
<!ELEMENT price    (#PCDATA)>
]>
<bookstore>
<book ISBN="0123456001">
<title>Java For Dummies</title>
<author>Tan Ah Teck</author>
<category>Programming</category>
<year>2009</year>
<edition>7</edition>
<price>19.99</price>
</book>
<book ISBN="0123456002">
<title>More Java For Dummies</title>
<author>Tan Ah Teck</author>
<category>Programming</category>
<year>2008</year>
<price>25.99</price>
</book>
<book ISBN="0123456010">
<title>The Complete Guide to Fishing</title>
<author>Bill Jones</author>
<author>James Cook</author>
<author>Mary Turing</author>
<category>Fishing</category>
<category>Leisure</category>
<language>French</language>
<year>2000</year>
<edition>2</edition>
<price>49.99</price>
</book>
</bookstore>

Explanation: Above XML document displays a BookStore in XML file.

Output:

Output -1.4

Example #3 – Parsing XML File

hello.html

<!DOCTYPE html>
<html>
<body>
<h1>Parsing XML File</h1>
<div>
<b>Email-Id:</b> <span id="Email-Id"></span><br>
<b>Password</b> <span id="Password"></span><br>
<b>Message:</b> <span id="message"></span>
</div>
<script>
var xmlh, xmlDo;
xmlh = new XMLHttpRequest();
xmlh.open("GET", "hello.xml", false);
xmlh.send();
xmlDo = xmlh.responseXML;
document.getElementById("Email-Id").innerHTML=
xmlDo.getElementsByTagName("Email-Id")[0].childNodes[0].nodeValue;
document.getElementById("Password").innerHTML=
xmlDo.getElementsByTagName("Password")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDo.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>
</body>
</html>

Explanation: The above code uses XML document to Parse an individual XML file.

Output:

Output -1.5

Example #4 – XML file in the format in DOCMAKER

<?xml version="1.0" encoding="UTF-8"?>
<DOCUMENT TYPE="RPWIP" VERSION="10.3">
<DOCSET NAME=" form">
<MOXFILE NAME="air567"/>
<GROUP NAME="" NAMEX="Hello" NAME2="VERSION 103">
<FORM NAME="Copyright - Basic" OPTIONS="R">
<DESCRIPTION>Copyright - Basic Description Part</DESCRIPTION>
<FIELD NAME="First">8:20 PM</FIELD>
<FIELD NAME="Last">6:30PM</FIELD>
<RECIPIENT NAME="Cust" COPYCOUNT="2" CODE="" SEQUENCE="2"/>
<RECIPIENT NAME="Head" COPYCOUNT="2" CODE=""
SEQUENCE="3"/>
<RECIPIENT NAME="Democractic" COPYCOUNT="2" CODE="" SEQUENCE="4"/>
:
</FORM>
</GROUP>
</DOCSET>
</DOCUMENT>

Explanation: The above code is done for Document marker workstation where it lists few tags for defining a .DAT file in DOCSET and field tag for forms and Group keys tags.

Output:

 Output -1.6

Conclusion

To the end, XML files practically model a hierarchical Database. Each Position specified in an XML hierarchy implements the relationships to other elements in the code. Therefore, in this article, we have seen how to work with files in .xml extensions and demo examples of various cases. This XML file could be implemented in Other programming Languages to retrieve the data from the XML document.

Recommended Articles

This is a guide to XML File. Here we also discuss the introduction and how file work in xml? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. PHP XML Parser
  2. XML Element
  3. XML Technologies
  4. XML Attributes
0 Shares
Share
Tweet
Share
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

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

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

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

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

EDUCBA Login

Forgot Password?

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

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

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

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

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

Let’s Get Started

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