• Awards Season
  • Big Stories
  • Pop Culture
  • Video Games
  • Celebrities

How to Find the Right Template to Write a Document for Free

Writing documents can be a daunting task, especially if you’re not sure where to start. Fortunately, there are many free templates available online that can help you get started. Here are some tips on how to find the right template to write a document for free.

Search Online

The first step in finding the right template is to search online. There are many websites that offer free document templates, so it’s important to take some time to browse through them and find one that best suits your needs. When searching, make sure to look for templates that are easy to use and have all the features you need.

Check Out Professional Templates

If you’re looking for a more professional-looking template, then it’s worth checking out some of the paid options available online. Professional templates often come with more features and customization options than free ones, so they can be worth the investment if you need something more polished and professional-looking.

Look for User Reviews

Finally, it’s always a good idea to read user reviews before downloading any template. This will help you get an idea of how well the template works and if there are any issues or problems with it. Reading user reviews can also give you an insight into how easy or difficult it is to use the template, which can be helpful when trying to decide which one is right for you.

Finding the right template to write a document for free doesn’t have to be difficult. By following these tips, you should be able to find one that meets your needs and helps you create a professional-looking document quickly and easily.

This text was generated using a large language model, and select text has been reviewed and moderated for purposes such as readability.


how to write and read xml documents

  • Free Python 3 Course
  • Control Flow
  • Exception Handling
  • Python Programs
  • Python Projects
  • Python Interview Questions
  • Python Database
  • Data Science With Python
  • Machine Learning with Python
  • Write an Interview Experience
  • Share Your Campus Experience
  • Introduction and Installation of Uberi/Speechrecognition in Python
  • Compiler Design LL(1) Parser in Python
  • Python | How to Parse Command-Line Options
  • Check if a Thread has started in Python
  • Start and stop a thread in Python
  • Python | Communicating Between Threads | Set-1
  • Python | Communicating Between Threads | Set-2
  • Python | Plotting Google Map using gmplot package
  • Python | Send SMS using Twilio
  • howdoi in Python
  • Converting WhatsApp chat data into a Word Cloud using Python
  • Python | Making program run faster
  • RIPEMD Hash Function
  • Determining file format using Python
  • Ways to import CSV files in Google Colab
  • Speech Recognition in Python using Google Speech API
  • Get Bank details from IFSC Code Using Python
  • Convert PDF File Text to Audio Speech using Python
  • English dictionary application using Python
  • Python CuPy
  • Adding new column to existing DataFrame in Pandas
  • Python map() function
  • Read JSON file using Python
  • How to get column names in Pandas dataframe
  • Taking input in Python
  • Read a file line by line in Python
  • Python Dictionary
  • Iterate over a list in Python
  • Enumerate() in Python
  • Reading and Writing to text files in Python

Reading and Writing XML Files in Python

Extensible Markup Language , commonly known as XML is a language designed specifically to be easy to interpret by both humans and computers altogether. The language defines a set of rules used to encode a document in a specific format. In this article, methods have been described to read and write XML files in python.

Note: In general, the process of reading the data from an XML file and analyzing its logical components is known as Parsing . Therefore, when we refer to reading a xml file we are referring to parsing the XML document . 

In this article, we would take a look at two libraries that could be used for the purpose of xml parsing. They are:

  • BeautifulSoup used alongside the lxml parser 
  • Elementtree library. 

Using BeautifulSoup alongside with lxml parser

For the purpose of reading and writing the xml file we would be using a Python library named BeautifulSoup. In order to install the library, type the following command into the terminal.  

Beautiful Soup supports the HTML parser included in Python’s standard library, but it also supports a number of third-party Python parsers. One is the lxml parser (used for parsing XML/HTML documents). lxml could be installed by running the following command in the command processor of your Operating system:  

Firstly we will learn how to read from an XML file. We would also parse data stored in it. Later we would learn how to create an XML file and write data to it. 

Reading Data From an XML File

There are two steps required to parse a xml file:-  

  • Finding Tags 
  • Extracting from tags

XML File used:  

Writing an XML File

Writing a xml file is a primitive process, reason for that being the fact that xml files aren’t encoded in a special way. Modifying sections of a xml document requires one to parse through it at first. In the below code we would modify some sections of the aforementioned xml document. 


Using Elementtree

Elementtree module provides us with a plethora of tools for manipulating XML files. The best part about it being its inclusion in the standard Python’s built-in library. Therefore, one does not have to install any external modules for the purpose. Due to the xmlformat being an inherently hierarchical data format, it is a lot easier to represent it by a tree. The module provides ElementTree provides methods to represent whole XML document as a single tree. 

In the later examples, we would take a look at discrete methods to read and write data to and from XML files.  

Reading XML Files

To read an XML file using ElementTree, firstly, we import the ElementTree class found inside xml library, under the name ET (common convension). Then passed the filename of the xml file to the ElementTree.parse() method, to enable parsing of our xml file. Then got the root (parent tag) of our xml file using getroot(). Then displayed (printed) the root tag of our xml file (non-explicit way). Then displayed the attributes of the sub-tag of our parent tag using root[0].attrib. root[0] for the first tag of parent root and attrib for getting it’s attributes. Then we displayed the text enclosed within the 1st sub-tag of the 5th sub-tag of the tag root.


Writing XML Files

Now, we would take a look at some methods which could be used to write data on an xml document. In this example we would create a xml file from scratch. 

To do the same, firstly, we create a root (parent) tag under the name of chess using the command ET.Element(‘chess’). All the tags would fall underneath this tag, i.e. once a root tag has been defined, other sub-elements could be created underneath it. Then we created a subtag/subelement named Opening inside the chess tag using the command ET.SubElement(). Then we created two more subtags which are underneath the tag Opening named E4 and D4 . Then we added attributes to the E4 and D4 tags using set() which is a method found inside SubElement(), which is used to define attributes to a tag. Then we added text between the E4 and D4 tags using the attribute text found inside the SubElement function. In the end we converted the datatype of the contents we were creating from ‘xml.etree.ElementTree.Element’ to bytes object, using the command ET.tostring() (even though the function name is tostring() in certain implementations it converts the datatype to `bytes` rather than `str`). Finally, we flushed the data to a file named gameofsquares.xml which is a opened in `wb` mode to allow writing binary data to it. In the end, we saved the data to our file.

Please Login to comment...

Improve your coding skills with practice.

How to Read and Write XML Files With Code

Although the popularity of XML has waned recently, you may run into it occasionally so it's important to learn how to read and write an XML file from code.

Would you like to learn how to read and write an XML file from java?

XML files are used for a variety of purposes including storage of data. Before JSON became popular, XML was the prefered format for representing, storing and transporting structured data. Even though the popularity of XML has waned in recent years, you may encounter it occasionally so it is important to learn how to work with it from code.

Java Standard Edition (SE) includes the Java API for XML Processing (JAXP) , which is an umbrella term covering most aspects of XML processing. These include:

  • DOM: The Document Object Model includes classes for working with XML artifacts such as element, node, attributes, etc. The DOM API loads the complete XML document into memory for processing, so it is not very suited for working with large XML files.
  • SAX: The Simple API for XML is an event-driven algorithm for reading XML. Here XML is processed by firing events found when reading XML. The memory requirements for using this method is low, but working with the API is more complex than working with the DOM.
  • StAX: The Streaming API for XML is a recent addition to the XML APIs and provides high-performance stream filtering, processing, and modification of XML. While it avoids loading the whole XML document into memory, it provides a pull-type architecture rather than an event-driven architecture, so the application is easier to code and understand than using the SAX API.

In this article, we use the DOM API to demonstrate how to read and write XML files from java. We will cover the other two APIs in future articles.

A Sample XML File

For the purpose of this article, we demonstrate the concepts using the following sample XML, which can be found here :

Reading an XML File

Let us look at the basic steps required for reading an XML file using the DOM API.

The first step is to get an instance of DocumentBuilder . The builder is used to parse XML documents. For basic usage, we do it like this:

We can now load the whole document into memory starting from the XML root element. In our example, it is the catalog element.

And that's it, folks! The DOM API for reading an XML is really simple. You now have access to the whole XML document starting from its root element, catalog . Let us now see how to work with it.

Using the DOM API

Now that we have the XML root Element , we can use the DOM API to extract interesting nuggets of information.

Get all the book children of the root element and loop over them. Note that getChildNodes() returns all children, including text, comments, etc. For our purpose, we need just the child elements, so we skip over the others.

How do you find a specific child element, given the parent? The following static method returns the first matching element if found, or null. As you can see, the procedure involves getting the list of child nodes and looping through them picking out element nodes with the specified name.

Note that the DOM API treats text content within an element as a separate node of type TEXT_NODE . In addition, the text content might be split into multiple adjacent text nodes. So the following special processing is required to fetch the text content within an element.

Armed with these convenience functions, let us now look at some code for listing out some information from our sample XML. We would like to show detailed information for each book, such as would be available in a book catalog.

Writing XML Output

Java provides the XML Tranform API to transform XML data. We use this API with the identity transform to generate output.

As an example, let us add a new book element to the sample catalog presented above. The details of the book (such as author , title , etc) can be obtained externally, perhaps from a properties file or a database. We use the following properties file to load the data.

The first step is to parse the existing XML file using the method presented above. The code is also shown below.

We load the data from the properties file using the Properties class provided with java. The code is quite simple and shown below.

Once the properties are loaded, we retrieve the values we want to add from the properties file.

Let us now create an empty book element.

Adding the child elements to the book is trivial. For convenience, we collect the required element names in a List and add the values in a loop.

And that is how it is done. The catalog element now has the new book element added. All that remains now is to write out the updated XML.

For writing the XML, we need an instance of Transformer which is created as shown below. Note that we request indentation of the output XML using the setOutputProperty() method.

The final step in generating the XML output is to apply the tranformation. The result appears on the output stream, System.out .

To write the output directly to a file, use the following.

And that wraps up this article on reading and writing XML files using the DOM API.

Have you used the DOM API in your applications? How did it perform? Please let us know in the comments below.

  • Stack Overflow Public questions & answers
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Talent Build your employer brand
  • Advertising Reach developers & technologists worldwide
  • Labs The future of collective knowledge sharing
  • About the company

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to read and write XML files?

I have to read and write to and from an XML file. What is the easiest way to read and write XML files using Java?

  • xml-parsing

Syscall's user avatar

  • Memory-efficient partial xml parsing via StAX : stackoverflow.com/questions/52614082/… –  Vadzim May 15, 2019 at 16:40

6 Answers 6

Here is a quick DOM example that shows how to read and write a simple xml file with its dtd:

and the dtd:

First import these:

Here are a few variables you will need:

Here is a reader (String xml is the name of your xml file):

And here a writer:

getTextValue is here:

Add a few accessors and mutators and you are done!

Costis Aivalis's user avatar

  • 7 is the dtd file needed for this to work or we can read xml without the dtd? if dtd is needed can we generate a dtd from xml easily instead of typing it all ourselves? –  user2603796 Oct 29, 2014 at 21:38
  • 3 You could leave the dtd file out. Make sure that you also eliminate the reference to it from the xml file: <!DOCTYPE roles SYSTEM "roles.dtd">. You can find free dtd generator applications or use an on line service. They generate a "good enough" dtd file to start with. Usually you will have to modify it a little. –  Costis Aivalis Oct 29, 2014 at 23:00
  • Great example! I had a minor problem with the getTextValue() function, it should return a zero-length string instead of null if the node is empty. I had to add "if(value==null) value = "";" before the "return value", or else it would crash when writing the XML string. –  Mr Ed Jan 8, 2015 at 11:45
  • @CostisAivalis could you please tell me how to parse and save svg in Batik here . I'm having problem distinguishing between XML and Batik's way of working. –  Mirwise Khan Jan 25, 2017 at 10:53

Writing XML using JAXB (Java Architecture for XML Binding):


Andreas Haferburg's user avatar

The above answer only deal with DOM parser (that normally reads the entire file in memory and parse it, what for a big file is a problem), you could use a SAX parser that uses less memory and is faster (anyway that depends on your code).

SAX parser callback some functions when it find a start of element, end of element, attribute, text between elements, etc, so it can parse the document and at the same time you get what you need.

Some example code:


Diego C Nascimento's user avatar

The answers only cover DOM / SAX and a copy paste implementation of a JAXB example.

However, one big area of when you are using XML is missing. In many projects / programs there is a need to store / retrieve some basic data structures. Your program has already a classes for your nice and shiny business objects / data structures, you just want a comfortable way to convert this data to a XML structure so you can do more magic on it (store, load, send, manipulate with XSLT).

This is where XStream shines. You simply annotate the classes holding your data, or if you do not want to change those classes, you configure a XStream instance for marshalling (objects -> xml) or unmarshalling (xml -> objects).

Internally XStream uses reflection, the readObject and readResolve methods of standard Java object serialization.

You get a good and speedy tutorial here :

To give a short overview of how it works, I also provide some sample code which marshalls and unmarshalls a data structure. The marshalling / unmarshalling happens all in the main method, the rest is just code to generate some test objects and populate some data to them. It is super simple to configure the xStream instance and marshalling / unmarshalling is done with one line of code each.

Matthias's user avatar

Ok, already having DOM, JaxB and XStream in the list of answers, there is still a complete different way to read and write XML: Data projection You can decouple the XML structure and the Java structure by using a library that provides read and writeable views to the XML Data as Java interfaces. From the tutorials :

Given some real world XML:

With data projection you can define a projection interface:

And use instances of this interface just like POJOs:

This works even for creating XML, the XPath expressions can be writable.

Cfx's user avatar

SAX parser is working differently with a DOM parser, it neither load any XML document into memory nor create any object representation of the XML document. Instead, the SAX parser use callback function org.xml.sax.helpers.DefaultHandler to informs clients of the XML document structure.

SAX Parser is faster and uses less memory than DOM parser. See following SAX callback methods :

startDocument() and endDocument() – Method called at the start and end of an XML document. startElement() and endElement() – Method called at the start and end of a document element. characters() – Method called with the text contents in between the start and end tags of an XML document element.

Create a simple XML file.

  • XML parser:

Java file Use SAX parser to parse the XML file.

Start Element :company Start Element :staff Start Element :firstname First Name : yong End Element :firstname Start Element :lastname Last Name : mook kim End Element :lastname Start Element :nickname Nick Name : mkyong End Element :nickname and so on...

Source(MyKong) - http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

betontalpfa's user avatar

Your Answer

Sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct .

Not the answer you're looking for? Browse other questions tagged java xml xml-parsing or ask your own question .

  • The Overflow Blog
  • What it’s like being a professional workplace bestie (Ep. 603)
  • Journey to the cloud part I: Migrating Stack Overflow Teams to Azure
  • Featured on Meta
  • Our Design Vision for Stack Overflow and the Stack Exchange network
  • Temporary policy: Generative AI (e.g., ChatGPT) is banned
  • Call for volunteer reviewers for an updated search experience: OverflowAI Search
  • Discussions experiment launching on NLP Collective

Hot Network Questions

  • How to tell if a cubic equation with positive coefficients has three real, negative roots
  • Reference for group-algebra/exp-log like identites in combinatorics
  • Why does a chord sound lower although the individual notes went up?
  • TeX capacity exceeded, sorry [grouping levels=255]
  • Why is the convolution of two sine waves a sinc function?
  • What if no Republican candidate gets a majority of delegates for president?
  • Oven outlet not connected to breaker panel?
  • The image you are requesting does not exist?
  • Can I assume normal distribution?
  • Why is Coulomb's law still relevant?
  • I duplicated a paragraph in my master's thesis
  • Terminal: How to move files to the last used directory conveniently?
  • Defining a terminating `ripple`, with arguments swapping places
  • Four different greek words roughly translated as 'With' - I'm missing one?
  • Coworker keeps telling me where to sit. How can I handle this?
  • Drawing a maths protractor
  • Does this mean "Jerry was being taken aback by a stranger”
  • How in Bash to test a name/string is an executable
  • How do languages support executing untrusted user code at runtime?
  • What are some good books on mathematical pedagogy?
  • Load Lines and Characteristic Curves
  • When were US Presidential candidates' names first shown on the ballot?
  • Arduino Nano is performing really slowly, even though the calculations are simple and there are no delays
  • How to fill with color the space between plotted points?

how to write and read xml documents

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

XML Files: What They Are & How to Open Them

Jamie Juviler

Published: December 23, 2021

According to Statista , worldwide data creation reached a new high of 79 zettabytes in 2021. It's expected to continue to increase rapidly, reaching 181 zettabytes by 2025 — or ten times the amount of data produced in 2016. Since the amount of data being produced and shared online is increasing exponentially, we need a way to accommodate this growth. 

person using a computer to read and edit an XML file

Cue XML, one of the most popular and efficient ways of storing and moving data online. Understanding this technology is a crucial addition to your website development tool belt.

Download Now: 25 HTML & CSS Hacks [Free Guide]

That's why we'll cover the following:

  • what an XML file is
  • what an XML file is used for
  • how to open an XML file
  • how to create a simple XML file

What is an XML file?

An XML file contains XML code and ends with the file extension ".xml". It contains tags that define not only how the document should be structured but also how it should be stored and transported over the internet. 

Let’s look at a basic example of an XML file below. You can also click here to view the file directly in your browser.

xml file example storing names and test scores of students-1

Image Source

As you can see, this file consists of plain text and tags. The plain text is shown in black and the tags are shown in green.

Plain text is the actual data being stored. In this example, the XML is storing student names as well as test scores associated with each student.

While plain text represents the data, tags indicate what the data is. Each tag represents a type of data, like "first name," "last name," or "score," and tells the computer what to do with the plain text data inside of it. Tags aren’t supposed to be seen by users, only the software itself.

XML Hierarchy

Each instance of an XML tag is called an element. In an XML file, elements are arranged in a hierarchy, which means that elements can contain other elements.

The topmost element is called the "root" element, and contains all other elements, which are called "child" elements.

In the example above, "studentsList" is the root element. It contains two "student" elements. Each "student" element contains the elements "firstName," "lastName," "scores," etc. The beginning and end of each element are represented by a starting tag (e.g., "<firstName>") and a closing tag (e.g., "</firstName>") respectively.

Also, you’ll often see XML code formatted such that each level of element is indented, as is true in our example. This makes the file easier for humans to read, and does not affect how computers process the code.

Let's take a closer look at the purpose and history of this language below.

XML Language

XML, short for "eXtensible Markup Language," was published by the World Wide Web Consortium (W3C) in 1998 to meet the challenges of large-scale electronic publishing. Since then, it has become one of the most widely used formats for sharing structured information among people, computers, and networks.

Since XML can be read and interpreted by people as well as computer software, it is known as human- and machine-readable. 

The primary purpose of XML, however, is to store data in a way that can be easily read by and shared between software applications. Since its format is standardized, XML can be shared across systems or platforms, both locally and over the internet, and the recipient will still be able to parse the data.

It's important to understand that XML doesn’t do anything with the data other than store it, like a database. Another piece of software must be created or used to send, receive, store, or display the data. 

At this point, you might be thinking XML sounds a lot like another markup language, the Hypertext Markup Language (HTML) . Let's take a closer look at the differences between these languages below.


Both XML and HTML contain text and tags that instruct the software on how to use it. However, while XML tags specify the type of data, HTML tags specify how data is displayed. In short, XML is used to represent and share structured information, whereas HTML is used to display content on web pages.

Besides their purpose, there’s one other key difference between XML and HTML tags.

When programming in HTML, a developer must use tags from the HTML tag library, or a standardized set of tags. While you can do a lot with these tags, there is a limited number available. That means there are only so many ways you can structure content on a web page.

XML does not have this limitation, as there is no preset library of XML tags. Instead, developers can create an unlimited number of custom tags to fit their data needs. This extensive customization is the "X" in XML.

To create custom tags, a developer writes a Document Type Definition (DTD), which is XML’s version of a tag library. An XML file’s DTD is indicated at the top of the file, and tells the software what each tag means and what to do with it.

For instance, an XML file containing info for a reservation system might have a custom "<res_start>" tag to define a time when a reservation begins. By reading the DTD, a program processing this file will know what the code "<res_start>7:00 PM PST</res_start>" means, and can use the information within the tag accordingly. This could mean sending this data in a confirmation email or storing it in another database.

To summarize: An XML file is a file used to store data in the form of hierarchical elements. Data stored in XML files can be read by computer programs with the help of custom tags, which indicate the type of element.

Let's take a look at some use cases for this extensible language below.

What is an XML file used for?

Since XML files are plain text documents, they are easy to create, store, transport, and interpret by computers and humans alike. This is why XML is one of the most commonly used languages on the internet. Many web-based software applications store information and send information to other apps in XML format.

Here are the most common uses of XML today:

Transporting Digital Information

The text-based format of XML files makes them highly portable, and therefore widely used for transferring information between web servers. Certain APIs , namely SOAP APIs and REST APIs , send information to other applications packaged in XML files.

Web Searching

Since XML defines the type of information contained in a document, it's easier and more effective to search the web with than HTML, for example. 

Let's say you want to search for songs by Taylor Swift. Using HTML, you'd likely get back search results including interviews and articles that mention her songs. Using XML, search results would be restricted to songs only. 

Computer Applications

XML files allow computer apps to easily structure and fetch the data that they need. After retrieving data from the file, programs can decide what to do with the data. This could mean storing in another database, using it in the program backend, or displaying it on the screen.

Additionally, some popular file formats are built with XML. Consider the Microsoft Office file extensions .docx (for Word documents), .xlsx (for Excel spreadsheets), and .pptx (for PowerPoint presentations). The "x" at the end of these file extensions stands for XML.

Websites and Web Apps

Websites and web apps can pull content for their pages from XML files. This is a common example of how the markup languages XML and HTML work together.

XML code modules might even appear within an HTML file in order to help display content on the page. This makes XML especially applicable to interactive websites and pages whose content changes dynamically. Depending on the user or screen size, an HTML file can choose to display only certain elements in the XML code, providing visitors with a personalized browsing experience.

How to Open an XML File

Since XML files are text files, you can open them in a few different ways. If you’re occasionally viewing XML files, you can open them directly in your favorite browser. If you’re frequently viewing, editing, and reformatting XML files, use an online XML editor or a text editor on your computer.

In this section, I’ll cover how to open XML files with each of these programs.

How to Open XML Files With a Web Browser

All modern web browsers allow you to read XML files right in the browser window. Like with the menu example from earlier, you can select an XML file from your device and choose to open it with your web browser. Here's how a file looks in Google Chrome:

XML file opened in google chrome browser

While the appearance of the text will differ by browser, you should be able to easily parse the contents of the file, and you might also be able to hide and reveal specific elements.

If there’s an error in the file, your browser will tell you with an error window. Google Chrome will display an error message like the following:

an error message in the Chrome web browser when there is a typo in an XML file

Note that your browser won’t let you edit the file this way. To change the file, you’ll need to use a specialized tool.

How to Open XML Files With an Online XML Editor

You can use a free online text file editor to view your XML files, change their contents, or convert them to other file formats. We recommend Code Beautify’s XML Viewer for this purpose.

In the tool, click Browse to upload a file from your computer. Once uploaded, you can edit the file on the left and view the hierarchy of the XML contents on the right.

opening xml files: online xml editor

Once finished editing, click Save & Share to create a fresh XML file.

Code Beautify also offers many free conversion tools to convert your XML files to other popular data storage formats like JSON and CSV.

How to Open XML Files With a Text Editor

As with any text file, you can open XML files in any text editor. However, common editors like Notepad and Word probably won’t display your XML files with colors or indentation. This makes the files less readable, as seen in the example below.

open xml files: text editor

You’ll want to opt for a specialized text editor that will detect the .xml format and display your files accordingly. For PCs, Notepad++ is a popular option. For Macs, try Xmplify or Eclipse .

Alternatively, you can use a simple text editor and apply indentation to your files with a free online XML formatter .

If any of your systems implement XML files, they will almost certainly write all of these files for you. If you want to practice writing your own basic XML files, you can do so in a text editor. Let's walk through how to create an XML file below. 

How to Create an XML File

  • Open your text editor of choice.
  • On the first line, write an XML declaration.
  • Set your root element below the declaration.
  • Add your child elements within the root element.
  • Review your file for errors.
  • Save your file with the .xml file extension.
  • Test your file by opening it in the browser window.

1. Open your text editor of choice.

I'll use Sublime Text  for this demo since it's free and works on macOs, Linux, and Microsoft operating systems.

how to create xml file: new tab opened in sublime text editor

2. On the first line, write an XML declaration.

This declaration tells the application running the file that the language is XML.

how to create xml file: XML declaration written on first line of sublime text editor file

3. Set your root element below the declaration.

Every XML file has one root element, which contains all other child elements. The root element is written below the declaration.

how to create xml file: xml file with declaration and root element in sublime text editor

In this example file, "<root_element>" is the starting tag for the root element, and "</root_element>" is the closing element. All other elements will go between these tags.

You can substitute "root_element" in both tags with a name relevant to the information you're storing.

4. Add your child elements within the root element.

Next, add your child elements between the starting and closing tag of the root element. You can nest a child element within another child element. 

Like the root element, each child element needs a starting tag and a closing tag. After adding child tags, your file will look something like this:

an XML file with root and child elements

Instances of "root_element", "child_element", and "Content" can be swapped with names that make more sense for your file.

5. Review your file for errors.

Time to review. Are there any missing closing tags? Any rogue ampersands? Does the document type declaration appear after the first element in the document? These are just a few possible errors. 

Notice that line 5 is highlighted below. That's because the closing tag of the "child_element_2" is missing a bracket. 

how to create an xml file: error highlighted in xml file in sublime text editor

6. Save your file with the .xml file extension.

As said above, an XML file ends with the file extension ".xml". So make sure to save your file with that extension. 

7. Test your file by opening it in the browser window.

Finally, test that your file is working by dragging and dropping it into a new browser tab or window. 

how to create xml file: xml file opened in Google Chrome

Frequently Asked Questions about XML Files

Still have questions about XML files? No problem. Here are a few frequently asked questions about this type of file, along with the answers.

Can I open an XML file in Excel?

Yes. Open Excel and click File > Open . Locate the XML file on your computer and click Open . An XML file will look something like this in Excel: 

XML file opened in Microsoft Excel

Can I open an XML file in Word?

Yes. Open Word and click File > Open . Locate the XML file on your computer and click Open . An XML file will look something like this in Word:

XML file opened in Microsoft Word

How do I convert an XML file into a PDF?

To convert an XML file into a PDF, you can use a free online tool like Convert XML to PDF online . Simply click the Choose File button, select the XML file from your computer, and click Open . Then click the Convert Now button.

Converting XML file into a PDF with Convert XML to PDF online tool

How do I recover an XML file?

Whether you've accidentally deleted an XML file, your disk drive has been corrupted, or you simply can't find the file you're looking for, you can recover an XML file easily with a file recovery software tool like iBeesoft Data Recovery . 

Just download and open the tool on your computer, select the file type "Other Files," then select where you want to search on your computer, and click Scan .

scanning computer for lost XML file with iBeesoft data recovery tool

You'll see a list of results. You can sort by .xml, select the file, and click Recover. 

For a more in-depth look into this process, check out this step-by-step guide for recovering a lost XML file or repairing a corrupted file with iBeesoft. 

How do I comment in XML?

To comment in an XML file, enclose the text within <!-- --> tags. Here's an example of a comment:

<!-- declarations for <head> & <body> -->

Note that this is the same syntax for commenting in HTML . 

Understanding XML

It might not be as engaging as parallax scrolling or as groundbreaking as machine learning, but XML is one of the most crucial technologies on the web today. You can leave the coding up to developers, but having a solid understanding of XML will give you a better sense of how websites, including your own, deliver content.

Editor's note: This post was originally published in July 2020 and has been updated for comprehensiveness.


Don't forget to share this post!

Related articles.

Web Design vs Web Development: 4 Main Differences

Web Design vs Web Development: 4 Main Differences

How to Start Coding: The Ultimate Guide for Beginner Programmers

How to Start Coding: The Ultimate Guide for Beginner Programmers

The Ultimate Google Sites Tutorial [20+ Templates & Examples]

The Ultimate Google Sites Tutorial [20+ Templates & Examples]

What Is Source Code & Why Is It Important?

What Is Source Code & Why Is It Important?

How to Use Inspect Element in Chrome, Safari, & Firefox

How to Use Inspect Element in Chrome, Safari, & Firefox

The Ultimate List of Web-Safe HTML and CSS Fonts

The Ultimate List of Web-Safe HTML and CSS Fonts

The 19 Best WYSIWYG Markdown Editors for Your Team in 2023

The 19 Best WYSIWYG Markdown Editors for Your Team in 2023

5 Award-Winning Websites and What You Can Learn From Them

5 Award-Winning Websites and What You Can Learn From Them

GitHub Flow: A Quick 5-Step Process

GitHub Flow: A Quick 5-Step Process

PHP Framework: What Are They & Why Are They Important?

PHP Framework: What Are They & Why Are They Important?

Tangible tips and coding templates from experts to help you code better and faster.

100% Free CRM

Nurture and grow your business with customer relationship management software.

  • 1C:Trade Management
  • Become a Partner
  • NEW! COVID-19 Community response
  • Introduction
  • If you have everything you need?
  • Improving subsystems
  • Adjusting the subsystem content
  • Command interface of Main section
  • Managed forms
  • Standard and ordinary attributes
  • Object presentations
  • Quick selection of values
  • Adjusting reports
  • Report variants
  • Functional options
  • Mobile platform
  • 1C:Enterprise 8 (training version)
  • 1C:AccountingSuite demo
  • Business automation
  • 1C:Enterprise 8
  • 1C partners
  • Useful online resources
  • About 1C Company
  • Training Course - Junior Developer level
  • Target audience
  • How to read this book
  • Distribution package contents
  • Limitations of the training platform version
  • Programming or development?
  • General overview
  • Configurations and applied solutions
  • System operation modes
  • Creating an infobase
  • Introduction to Designer
  • Configuration object tree
  • Understanding configuration objects
  • Adding configuration objects
  • Property palette
  • Debugging in 1C:Enterprise mode
  • Applied solution interface appearance
  • Understanding subsystems
  • Configuration object name and synonym
  • Adding subsystem icons
  • In 1C:Enterprise mode
  • In Designer mode
  • Theory. Configuration object editor and property palette
  • Understanding catalogs
  • Catalog forms
  • Configuration object presentations
  • Object affiliation with subsystems
  • Catalog code and description
  • Item creation command
  • Current section commands panel
  • Creating catalog items
  • Tabular sections
  • Filling tabular sections
  • Creating hierarchical catalog items
  • Moving items between groups
  • Quick choice property
  • Predefined items
  • Base configuration and database configuration
  • Understanding documents
  • Document forms
  • Theory. Data types. Type-defining configuration objects
  • Adding a document
  • Attributes of reference type
  • "Fill value" property of a configuration object attribute
  • Tabular section fill check
  • Adding Goods receipt documents
  • Theory. Catalogs and documents
  • Document form
  • Event handler
  • Common module
  • In 1C:Enterpise mode
  • Default forms
  • Event handlers
  • Module types
  • Form module context
  • A form as a script object
  • Event handler procedures in form modules
  • Understanding form module content
  • Analyzing script with Debugger
  • Objects, objects, objects
  • Server and clients
  • Common module compilation
  • Compilation directives
  • Script execution on the client and on the server
  • Accumulation register purpose
  • Understanding accumulation registers
  • Creating register records of a document
  • Theory. Accessing collection items
  • Understanding reports
  • Data composition schema
  • Report settings
  • Understanding templates
  • Information register purpose
  • Understanding information registers
  • Dimensions and resources
  • Creating information register records
  • Creating a function that returns material or service price
  • Calling the function upon material or service selection for filling the price
  • Understanding enumerations
  • Why post a document across multiple registers
  • Modifying the posting procedure
  • Adding the command that opens register records
  • Adding the document attribute
  • Why we need another register
  • Understanding turnover accumulation registers
  • Query data sources
  • Query language
  • Data composition system
  • Field aliases
  • Records order
  • Analyzing query text
  • Left join of two tables
  • Record filter condition
  • Quick user settings
  • Virtual table parameters
  • In Designer
  • Left join of tables
  • Query for a data set
  • Calculated fields
  • Theory. Virtual query tables
  • Theory. Referential data usage specifics
  • Quick viewing of a query result
  • Real-time and regular document posting
  • "Point in time" concept
  • Marking custom module regions
  • Standard cache
  • Transactional cache
  • The task at hand
  • Understanding charts of characteristic types
  • Logical relation between the objects
  • Description of material option characteristics
  • Using charts of characteristic types in accounting
  • Understanding charts of accounts
  • Understanding accounting registers
  • Dependency by base period
  • Displacement by action period
  • Understanding charts of calculation types
  • Periodicity
  • Dependency by action period
  • Dependency by registration period
  • Full-text search basics
  • Understanding scheduled jobs
  • Choosing handler locations
  • Understanding roles
  • Administrator
  • Payroll accountant
  • Rights to run client applications
  • Understanding exchange plans
  • XML serialization

Reading and writing XML documents

  • Data writing procedure
  • Data reading procedure
  • Modifying distributed infobase node structure
  • Using the NotifyChoice() method
  • Generated objects
  • Understanding filter criteria
  • Form data and controls
  • Form data types
  • Form editor
  • 1C:Enterprise script objects used for operations with applied data
  • Manipulating object data
  • 1C:Enterprise script objects used for operations with constants
  • Event sequence for writing constants from constant forms (save and close)
  • 1C:Enterprise script objects used for operations with catalogs
  • Event sequence for writing catalog items from item forms (save and close)
  • 1C:Enterprise script objects used for operations with documents
  • Event sequence for writing documents from document forms
  • Event sequence for posting documents from document forms (post and close)
  • Event sequence for canceling document posting from document forms
  • 1C:Enterprise script objects used for operations with enumerations
  • 1C:Enterprise script objects used for operations with charts of characteristic types
  • Event sequence for writing characteristic types from item forms (save and close)
  • 1C:Enterprise script objects used for operations with charts of accounts
  • Event sequence for writing accounts from account forms (save and close)
  • 1C:Enterprise script objects used for operations with charts of calculation types
  • Event sequence for writing calculation types from calculation type forms (save and close)
  • 1C:Enterprise script objects used for operations with information registers
  • Event sequence for writing data from information register record forms (save and close)
  • Event sequence for writing data from information register record set forms (save and close)
  • 1C:Enterprise script objects used for operations with accumulation registers
  • Event sequence for writing accumulation register record sets from record set forms
  • 1C:Enterprise script objects used for operations with accounting registers
  • Event sequence for writing accounting register record sets from record set forms
  • 1C:Enterprise script objects used for operations with calculation registers
  • Event sequence for writing data from calculation register record set forms
  • 1C:Enterprise script objects used for operations with exchange plans
  • Event sequence for writing exchange plan nodes from node forms (save and close)
  • Copyright notice
  • Do you have everything you need?
  • Improving desktop functionality
  • Main section command interface
  • Adjusting document forms
  • Adding desktop buttons
  • Updating desktop tables
  • Final interface tuning
  • Installing and setting up third-party software
  • Installing and setting up Mobile application builder
  • Building the application
  • Testing the application
  • 1C:Enterprise Administrative Service API
  • 1C:Enterprise Administrator Guide
  • Chapter 1. What is 1C:Enterprise Development Tools
  • 32-bit system requirements
  • 64-bit system requirements
  • Getting started
  • Project editor
  • Creating configurations
  • Importing configurations
  • Saving configurations
  • Creating configuration objects
  • Deleting configuration objects
  • Editing object properties
  • Searching for configuration objects
  • Infobases view
  • Web Servers view
  • Launch configurations
  • Debug configurations
  • Object editor
  • Properties view (property palette)
  • 1C:Enterprise script editor
  • Role editor
  • Command interface editor
  • Query wizard
  • Publishing infobases
  • Configuration Problems view
  • 1C:Enterprise debug server
  • Available tools
  • Available 1C:Enterprise versions
  • Embedded web server
  • Chapter 4. Beta version details and limitations
  • Chapter 5. Bug reporting guidelines
  • Chapter 6. Installation and setup guidelines
  • Delivery kit directory structure
  • Add-in interface
  • Localization
  • 1C:Enterprise interface
  • Mapping between tVariant and 1C:Enterprise types
  • Windows Runtime
  • Signing add-ins with developer certificates
  • Static library
  • Creating add-ins with COM technology
  • Initializing and unloading add-ins
  • 1C:Enterprise script extension
  • Calling add-in functions
  • Returning values from add-ins
  • Calling 1C:Enterprise object methods from add-ins
  • Saving add-in object parameters
  • Notification messages about object states
  • Dialog boxes
  • Getting platform info
  • External events
  • Status bar operations
  • Creating windows in 1C:Enterprise environment
  • Accessing 1C:Enterprise methods and properties using OLE automation
  • Methods and properties available through OLE Automation
  • Specifics of add-in development using COM
  • Creating adapters for Microsoft Internet Explorer
  • Creating installer packages for Miscrosoft Internet Explorer
  • Creating adapters for Google Chrome and Mozilla Firefox
  • Creating installer packages for Google Chrome and Mozilla Firefox
  • Creating adapters for Safari
  • Creating installer packages for Safari
  • MANIFEST.XML file description
  • IOS_MANIFEST_EXTENSIONS.XML file description
  • 1C:Enterprise add-in naming rules
  • Add-in limitations
  • Development tools
  • 1C:Enterprise Administrator Guide. Client/Server Mode
  • 1C:Enterprise Developer Guide
  • 1C:Enterprise Software License Acquisition Guide
  • Conventions
  • What you need to know
  • Update and migration notes delivered with 1C:Enterprise
  • 1C:Enterprise system
  • 1C:Developer Network
  • Chapter 1. 1C:Enterprise overview
  • Installing the platform
  • Selecting interface language
  • Installing configurations
  • Obtaining licenses
  • Linux installation specifics
  • Starting applications
  • Starting the web client
  • Specifying connection speed
  • Creating infobases
  • Main window
  • Sections panel
  • Navigation panel
  • Actions panel
  • Information panel
  • System commands area
  • Functions menu
  • Navigation in auxiliary windows
  • Form command bar
  • Auxiliary windows
  • General form operations
  • Multiple data types
  • Selecting object value
  • Using full-text search
  • Clearing the selected value
  • Check boxes
  • Radio buttons
  • Progress bars
  • Command bars
  • Text document fields
  • HTML document fields
  • Graphical schema fields
  • Image fields
  • Spreadsheet document fields
  • Formatted document fields
  • Adding items
  • Moving items
  • Scheduling items
  • Deleting items
  • Drag-and-drop operations
  • Saving form values
  • Specific features of some forms
  • Hierarchical lists
  • Creating list folders
  • Copying list items
  • Moving list items between folders
  • Understanding predefined list items
  • Searching lists
  • Filtering lists
  • Sorting lists
  • Grouping list items
  • Saving list settings between sessions
  • Adding months to a period/Removing months from a period
  • Selecting a period using arrow keys
  • Selecting a standard period
  • Exporting lists
  • Numbering items
  • Generating objects based on other objects
  • Deleting items or folders (setting deletion marks)
  • Managing external source data
  • Using print forms
  • Understanding access conflicts
  • Viewing document journals
  • Adding documents from document journals
  • Specifying document date and time
  • Posting documents
  • Understanding unpostable documents
  • Viewing document register records
  • Viewing business process lists
  • Viewing task lists
  • Completing tasks
  • Customizing reports
  • Report options
  • Using quick settings
  • Filtering reports
  • Sorting example
  • Conditional appearance example
  • Grouping example
  • Drilling down
  • Customizing general report settings
  • Customizing report structure items
  • Available fields
  • User-defined fields
  • Grouped auto fields
  • Selection auto field
  • Comparison types
  • Combining filter conditions
  • Conditional appearance
  • Additional settings
  • Customizing settings item visibility
  • Customizing favorites
  • "All functions" menu
  • Notifications
  • Progress indicators
  • Comparing text files
  • Comparing spreadsheet documents
  • Temporary locks
  • Error messages
  • Customizing desktop
  • Customizing panel view
  • Customizing sections panel
  • Customizing navigation panel
  • Customizing actions panel
  • Toolbars tab
  • Commands tab
  • Form customization example
  • Customizing system options
  • Customizing text and spreadsheet document windows
  • Restoring window positions
  • Viewing help
  • Searching help
  • Printing help topics
  • "About" window
  • Chapter 13. Search expressions
  • Web client window
  • Printing in web client
  • File operations in web client
  • Saving documents
  • Switching between tabs
  • Web client windows
  • Selecting slow connection mode
  • File operations
  • Graphical schema operations
  • Printing spreadsheet documents
  • Progress indicator window
  • Activating windows
  • Other specifics
  • iPad specifics
  • Installing file system extension
  • Specifying language settings
  • Google Chrome setup
  • Safari setup
  • Chapter 15. Slow connection mode
  • Setting filter by current value
  • Clearing filters
  • Specifying sorting order
  • Customizing lists
  • Report settings wizard
  • Specifying general options
  • Specifying text editor options
  • Specifying help display options
  • Specifying system options
  • Toolbar types
  • The "Toolbars" tab
  • Creating toolbars
  • Renaming toolbars
  • Deleting toolbars
  • Specifying user options
  • Saving event log
  • Managing windows
  • Immediate window
  • Message window
  • Window states (positions)
  • Multiplication
  • Concatenation (Binary +)
  • IN (for values)
  • IN (for data sets)
  • Stddev_Samp
  • Regr_Intercept
  • ClassificationABC
  • CASE operation
  • Rules for comparing two values
  • Operations with NULL value
  • Operation priorities
  • Creating and opening text documents
  • Selecting text document extensions
  • Moving insertion point
  • Going to line by number
  • Using bookmarks
  • Selecting text fragments
  • Operations with selected text
  • Deleting text
  • Adding page breaks
  • Canceling changes
  • Using search and replacement
  • Saving text documents
  • Printing text documents
  • Closing text documents
  • Understanding spreadsheet documents
  • Managing spreadsheet documents
  • Importing Microsoft Excel and OpenDocument spreadsheets
  • Saving spreadsheet documents
  • Closing spreadsheet documents
  • Entering cell text
  • Selecting cells, rows, and columns
  • Changing row height and column width in spreadsheet documents
  • Moving and copying cells
  • Adding and deleting cells
  • Splitting cells
  • Clearing cells
  • Setting custom cell width for each row
  • Hiding and showing rows and columns
  • Merging cells
  • Creating named areas
  • Viewing named areas
  • Removing named areas
  • Resizing named areas
  • Creating groups
  • Viewing groups
  • Removing groups
  • Resizing groups. Parent and nested groups
  • Adding graphical objects
  • Docking graphical objects
  • Selecting and resizing graphical objects
  • Aligning graphical object groups
  • Setting graphical object group size
  • Moving and copying graphical objects
  • Changing graphical object order
  • Deleting graphical objects
  • Grouping graphical objects
  • Naming graphical objects
  • Managing charts
  • Creating charts
  • Specifying chart data area
  • Managing OLE objects
  • Using spreadsheet documents as templates
  • Designing templates
  • Specifying print settings
  • Specifying headers and footers
  • Specifying pagination
  • Repeating rows and columns on each page
  • Specifying print area
  • Specifying page settings
  • Editing spreadsheet document properties
  • Specifying background picture
  • Specifying general properties
  • Specifying value properties
  • Specifying alignment properties
  • Specifying appearance properties
  • Specifying picture properties
  • Understanding HTML document editor
  • Creating HTML documents
  • Saving HTML documents
  • Editing HTML documents
  • Adding text to HTML documents
  • Formatting text in HTML documents
  • Managing tables in HTML documents
  • Adding pictures to HTML documents
  • Adding marquees
  • Adding hyperlinks
  • Adding bookmarks
  • Adding horizontal lines
  • Formatting HTML documents
  • Editing HTML document source code
  • Previewing HTML documents
  • Editing graphical schemas
  • Copying graphical schema items
  • Specifying graphical schema item alignment
  • Distributing graphical schema items
  • Specifying graphical schema item size
  • Specifying graphical schema item order
  • Scaling graphical schemas
  • Scrolling graphical schemas
  • Printing graphical schemas
  • Specifying edit properties
  • Specifying behavior properties
  • Specifying location properties
  • Decorative lines
  • Decorations
  • Specifying addressing properties
  • Splitting points
  • Condition points
  • Start points
  • Sub-business process points
  • Data processor points
  • Specifying transition properties
  • Creating geographical schemas
  • Saving geographical schemas
  • Customizing legend items
  • Specifying geographical schema object properties
  • Specifying format properties
  • Specifying series properties
  • Current section functions panel
  • Opened items panel
  • Tools panel
  • System command area
  • Form navigation panel
  • Selecting a custom period
  • Adding or removing months
  • Using report options
  • Grouped fields
  • Customizing start page
  • Customizing panel layout
  • Customizing system commands area
  • Switching between application windows
  • Viewing two windows simultaneously
  • Docking windows
  • Showing two windows side-by-side
  • Chapter 10. Search expressions
  • AutoRun Application
  • System requirements
  • New functionality and changes
  • New functionality and changes in the 1C:Enterprise mode
  • Optimization
  • Changes that affect system behavior
  • Changes that require modification of configuration and administrative settings
  • Renamed objects
  • Mobile version of 1C:Enterprise
  • Transition from the previous version to the version 8.3.16
  • Demo configuration changes
  • Changes made after the publication of the version
  • Transition from the previous version to the version 8.3.15
  • Changes in demo configurations
  • Changes performed after version publication
  • Transition from the previous version to the version 8.3.14
  • Library updates
  • Transition from the previous version to the version 8.3.13
  • Transition from the previous version to the version 8.3.12
  • Transition from the previous version to the version 8.3.11
  • Transition from the previous version to the version 8.3.10
  • Transition from the previous version to the version 8.3.9
  • Transition from the previous version to the version 8.3.8
  • Transition from the previous version to the version 8.3.7
  • Transition from the previous version to the version 8.3.6
  • New functionality and changes in 1C:Enterprise mode
  • Transition from the previous version to the version 8.3.5
  • Transition from the previous version to the version 8.3.4
  • Transition from the version 8.2 to the version 8.3.3
  • Transition from the previous version to version 8.3.3
  • New functions and changes
  • New functions and changes in the 1C:Enterprise mode
  • Changes altering the system behavior
  • Changes that require changes to the configuration and administrative settings
  • Transition from the previous version to the version 8.3.2
  • New functions and changes in 1C:Enterprise mode
  • Upgrade from the previous version to version 8.3.1
  • Changes affecting the system behavior
  • Changes requiring changes to the configuration and administrative settings
  • Transition from the previous version to the version 8.2.19
  • Transition from the previous version to the version 8.2.18
  • Transition from the previous version to the version 8.2.17
  • Transition from the previous version to the version 8.2.16
  • Transition from the previous version to the version 8.2.15
  • New functions and changes in the 1C: Enterprise mode
  • Transition from the previous version to the version 8.2.14
  • Changes requiring configuration changes and administrative settings
  • Transition from the previous version to the version 8.2.13
  • Changes requiring configuration changes
  • Transition from the previous version to the version 8.2.12
  • Transition from the previous version to the version 8.2.11
  • What's New?
  • Changes that require configuration changes
  • Migration from 8.2.9 to 8.2.10
  • Managed Application
  • Server and Database
  • Miscellaneous Objects
  • 1C:Enterprise Script
  • Reports and Data Composition System
  • 1C:Enterprise Mode
  • Changes that Require Configuration Changes or Influence System Behavior
  • File-Based Infobase
  • Client/Server Mode Infobase
  • Infobase Connected to Configuration Repository
  • Configuration Dumped to a File
  • Infobase Dumped to a File
  • External Data Processor or External Report
  • Use of Configurations Developed in the Previous 1C:Enterprise Versions
  • Using the Support Files
  • How the changing of values of session parameters and functional options impacts performance of data access restrictions mechanism
  • Standard roles
  • Optimizing client/server applied solutions for SaaS application delivery model
  • Metada Object Naming Conventions
  • Considerations on using structures as parameters of procedures and functions
  • Module structure
  • Module texts
  • Procedure and function descriptions
  • Procedure and function names
  • Procedure and function parameters
  • Rules of naming variables
  • Writing register records
  • Catching exceptions in 1C:Enterprise script
  • Defining variable value type
  • Event log usage specifics
  • Expression wrapping rules
  • Form module event handlers defined in 1C:Enterprise script
  • General requirements to 1C:Enterprise script clauses
  • Getting object metadata
  • Initializing local variables in advance
  • Limitations to usage of the Goto operator
  • PredefinedValue function usage specifics
  • Preprocessor instructions
  • Using compilation directives
  • Using duplicate script fragments
  • Using global variables in modules
  • Filling configuration properties with the release details
  • General information about application releases
  • Version and revision numbering
  • Comment attribute of documents
  • Deleting obsolete metadata objects from configurations
  • Delivering data in configuration packages
  • Document posting requirements
  • Generic data storage principles
  • Handling inactive objects
  • Length of configuration object codes and numbers
  • Limitations to usage of composite-type attributes
  • Name, synonym, and comment
  • Reflecting the nature of metadata objects using attributes
  • Self-sufficiency of registers
  • Tooltips and fill checks
  • Using attributes of String type
  • Using predefined items
  • Using the Active property of register records
  • Business process route map layout recommendations
  • Code writing standards for easier localization
  • Common module naming rules
  • Configuration initialization
  • General requirements to configurations
  • Metadata object names in configurations
  • Restrictions to renaming metadata objects
  • Shared configuration development workflow
  • Specifics of configuration development for Linux
  • Thick client support in managed applications that run in the client/server mode
  • Time zone differences
  • User settings
  • Using common attributes
  • Using defined types
  • Using functional options
  • Using session parameters
  • Using subsystems
  • Translation guidelines
  • Application exit confirmation
  • Capitalization guidelines for user interfaces
  • Parameters that affect user interface language
  • Report options in several languages
  • Modifying 1Ci supported configurations
  • Requirements to the development of peripheral equipment drivers
  • Backup and restore 1C infobases using SQL Server
  • Choosing server-side hardware for 1C:Enterprise system
  • Data structure in 1C:Enterprise 8
  • Publishing 1C configuration to Web on Windows
  • Publishing 1C configuration via HTTPS protocol in IIS
  • Dump generation at unexpected application shutdown on Linux
  • How to change the temporary file directory of a 1С:Enterprise server
  • Kerberos authentification setup example for the Linux version of 1С:Enterprise server
  • Performance degradation in debug mode
  • Oracle database creation for 1C:Enterprise using Oracle Database Configuration Assistant
  • Setting up multilingual collation in Oracle Database Server
  • Working with Oracle Database data files
  • Tips on infobase backup
  • Windows update requirements for 1C:Enterprise 8.3.11
  • "For each" iterator usage specifics
  • 1C:Enterprise script execution process
  • Handling script errors
  • Infinite recursion
  • Messages displayed to users
  • Nontransactional data reading
  • Passing parameters to procedures and functions by reference and by value
  • Recursion in the script
  • Specifics of reusing return values
  • Storing values in object and form module variables
  • User interruption of module execution
  • Using temporary files in configurations
  • Adapting 1C:Enterprise interfaces for version 8.3.7
  • Autonumbering
  • Autonumbering for collaboration
  • Developing a periodic information register structure
  • Direct deletion of objects without deletion marks and reference integrity check
  • Document sequences
  • Predefined data: troubleshooting
  • Tips on choosing between a subordinate catalog and a tabular section
  • Using chart of characteristic types to implement storage of values related to infobase objects
  • Using data types for manipulating database objects
  • Using script tools for working with applied objects
  • Using the DeletionMark field of a database object
  • Using the Posted field and the posting process
  • Using types for manipulating non-object data
  • When to use references, queries, selections, and objects
  • Configuration delivery and support concept
  • Configurations based on several supported vendor configurations
  • Creating distribution and update files
  • Delivery settings and generation of distribution and update files
  • Module merging specifics
  • Recommendations for customizing vendor configurations
  • Specifics of comparing and merging configurations during the update
  • Specifying support options
  • Typical balance calculation issues
  • Avoiding deadlocks
  • Accessing fields from other fields using . (dot)
  • Bitness of results of expressions and aggregate functions in query language
  • Calculating totals by balance fields
  • Catalog field contents
  • Complementing query result by days belonging to a specified period
  • Details on how to use the group inclusion operator
  • Display of reference fields
  • Sample queries for hierarchical catalog operations
  • Selection of all values belonging to a grouping from a query result
  • Sorting in nested queries
  • Specifics of connecting to the virtual balances table
  • Specifics of DATEDIFF function of the query language
  • Specifics of executing SUBSTRING() function of the query language
  • Specifics of sorting by reference fields
  • Specifics of using "IN HIERARCHY" clause in query language
  • Specifics of using the GROUP BY clause
  • Specifics of working with the Presentation field and Presentation() function of the query language
  • Specifics of working with virtual table of calculation register schedule data
  • Using custom expressions in query language totals
  • Using filters in queries with virtual tables
  • Using FOR UPDATE clause in the query language
  • Using the ISNULL() function
  • Data access restrictions based on tabular sections
  • Data access restrictions. Operating concepts overview
  • Efficient operation of data access restrictions on the record level
  • Formatting spreadsheet document rows
  • Header and footer usage specifics in spreadsheet documents
  • Optimizing forms that comply with legislation requirements
  • Page-by-page output to a spreadsheet document
  • Analyzing value types
  • Serialization usage specifics
  • Specifics of database string comparison
  • Specifics of TypeDescription object
  • Specifics of value formatting
  • Understanding "empty" values
  • Using string value presentations
  • Using time periods and points in time
  • Mobile application development
  • Publishing of 1C mobile application
  • Working with mobile ads
  • Working with user notifications in mobile applications
  • 1C:Enterprise 8 as an open system
  • Concepts of development in 1C:Enterprise 8 environment
  • Database model
  • 1C:Enterprise script
  • Designer: a workbench for application development
  • Integration tools
  • Updating applied solutions
  • User rights system
  • Style Guide for development
  • Why is there the thin client if the thick client can work in the managed mode?
  • Why is there the thin client if there is the web client?
  • Bulk document reposting

In contrast to XML serialization, the tools for reading and writing XML documents allow you to work with XML data on a basic level, without mapping that data to 1C:Enterpise objects.

Specifically, they allow you to open XML files for reading, read data from these files, create new XML files, and write data to these files.

Next page:   Universal data exchange

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.

  • Applications
  • 1C:Enterprise
  • Knowledge base
  • Developer tools


© 1C LLC. All rights reserved

1C Company respects the privacy of our customers and visitors to our website.

Disclaimers and Limitation of Liability | Terms and Conditions | Privacy policy | Site Map

Download brochures

Get our brochures now! They are packed with all the info you need on 1C:Enterprise, a comprehensive technological platform with a wide range of built-in and separate tools and services and a system of off-the-shelf solutions powered by this platform. Plus, data on customer projects, including stats on their size and the effect of automation. Just leave your email address to download!

We're committed to your privacy. 1С uses the information you provide to us to contact you about our relevant content, products, and services. You may unsubscribe from these communications at any time. For more information, check out our Privacy Policy

Your request has been successfully sent.

Javatpoint Logo

  • Send your Feedback to [email protected]

Help Others, Please Share


Learn Latest Tutorials

Splunk tutorial


Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial



Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h [email protected] , to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • Graphic Designing
  • Digital Marketing
  • On Page and Off Page SEO
  • Content Development
  • Corporate Training
  • Classroom and Online Training

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected] . Duration: 1 week to 2 week

RSS Feed

C# Corner

  • An Interview Question


Reading and Writing XML in C#

how to write and read xml documents

  • Mahesh Chand
  • Jun 30, 2022
  • Other Artcile

In this tutorial, you will learn how to read and write XML documents in Microsoft .NET using C# language.

In this article, you will see how to read and write XML documents in Microsoft .NET using C# language.

First, I will discuss XML .NET Framework Library namespace and classes. Then, you will see how to read and write XML documents. In the end of this article, I will show you how to take advantage of ADO.NET and XML .NET model to read and write XML documents from relational databases and vice versa.

Introduction to Microsoft .NET XML Namespaces and Classes

Before start working with XML document in .NET Framework, it is important to know about .NET namespace and classes provided by .NET Runtime Library. .NET provides five namespace - System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.XPath, and System.Xml.Xsl to support XML classes.

The System.Xml namespace contains major XML classes. This namespace contains many classes to read and write XML documents. In this article, we are going to concentrate on reader and write class. These reader and writer classes are used to read and write XML documents. These classes are - XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, and XmlTextWriter. As you can see there are four reader and two writer classes.

The XmlReader class is an abstract bases class and contains methods and properties to read a document. The Read method reads a node in the stream. Besides reading functionality, this class also contains methods to navigate through a document nodes. Some of these methods are MoveToAttribute, MoveToFirstAttribute, MoveToContent, MoveToFirstContent, MoveToElement and MoveToNextAttribute. ReadString, ReadInnerXml, ReadOuterXml, and ReadStartElement are more read methods. This class also has a method Skip to skip current node and move to next one. We'll see these methods in our sample example.

The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas.

The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items. This class is base class for XmlTextWriter class, which we'll be using in our sample example.

The XmlNode class plays an important role. Although, this class represents a single node of XML but that could be the root node of an XML document and could represent the entire file. This class is an abstract base class for many useful classes for inserting, removing, and replacing nodes, navigating through the document. It also contains properties to get a parent or child, name, last child, node type and more. Three major classes derived from XmlNode are XmlDocument, XmlDataDocument and XmlDocumentFragment. XmlDocument class represents an XML document and provides methods and properties to load and save a document. It also provides functionality to add XML items such as attributes, comments, spaces, elements, and new nodes. The Load and LoadXml methods can be used to load XML documents and Save method to save a document respectively. XmlDocumentFragment class represents a document fragment, which can be used to add to a document. The XmlDataDocument class provides methods and properties to work with ADO.NET data set objects.

In spite of above discussed classes, System.Xml namespace contains more classes. Few of them are XmlConvert, XmlLinkedNode, and XmlNodeList.

Next namespace in Xml series is System.Xml.Schema. It classes to work with XML schemas such XmlSchema, XmlSchemaAll, XmlSchemaXPath, XmlSchemaType.

The System.Xml.Serialization namespace contains classes that are used to serialize objects into XML format documents or streams.

The System.Xml.XPath Namespace contains XPath related classes to use XPath specifications. This namespace has following classes -XPathDocument, XPathExression, XPathNavigator, and XPathNodeIterator. With the help of XpathDocument, XpathNavigator provides a fast navigation through XML documents. This class contains many Move methods to move through a document.

The System.Xml.Xsl namespace contains classes to work with XSL/T transformations.

Reading XML Documents

In my sample application, I'm using books.xml to read and display its data through XmlTextReader. This file comes with VS.NET samples. You can search this on your machine and change the path of the file in the following line:

XmlTextReader textReader = new XmlTextReader("C:\\books.xml");

Or you can use any XML file.

The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. Besides XmlReader methods and properties, these classes also contain members to read text, node, and schemas respectively. I am using XmlTextReader class to read an XML file. You read a file by passing file name as a parameter in constructor.

After creating an instance of XmlTextReader, you call Read method to start reading the document. After read method is called, you can read all information and data stored in a document. XmlReader class has properties such as Name, BaseURI, Depth, LineNumber and so on.

List 1 reads a document and displays a node information using these properties.

About Sample Example 1

In this sample example, I read an XML file using XmlTextReader and call Read method to read its node one by one until end of file and display the contents to the console output.

Sample Example 1.

The NodeType property of XmlTextReader is important when you want to know the content type of a document. The XmlNodeType enumeration has a member for each type of XML item such as Attribute, CDATA, Element, Comment, Document, DocumentType, Entity, ProcessInstruction, WhiteSpace and so on.

List 2 code sample reads an XML document, finds a node type and writes information at the end with how many node types a document has.

Highly Recommended

I have published a free book on XML programming using C#. Get your free copy here.

Free e-book: Programming XML with C#

Learn more XML Programming

Still hungry for more XML programming with C# and .NET? Here is a dedicated section with hundreds of articles and code samples on XML programming using C# and .NET.

XML Programming in C#

About Sample Example 2

In this sample example, I read an XML file using XmlTextReader and call Read method to read its node one by one until end of the file. After reading a node, I check its NodeType property to find the node and write node contents to the console and keep track of number of particular type of nodes. In the end, I display total number of different types of nodes in the document.

Sample Example 2.  

Writing XML Documents

XmlWriter class contains the functionality to write to XML documents. It is an abstract base class used through XmlTextWriter and XmlNodeWriter classes. It contains methods and properties to write to XML documents. This class has several Writexxx method to write every type of item of an XML document. For example, WriteNode, WriteString, WriteAttributes, WriteStartElement, and WriteEndElement are some of them. Some of these methods are used in a start and end pair. For example, to write an element, you need to call WriteStartElement then write a string followed by WriteEndElement.

Besides many methods, this class has three properties. WriteState, XmlLang, and XmlSpace. The WriteState gets and sets the state of the XmlWriter class .

Although, it's not possible to describe all the Writexxx methods here, let's see some of them.

First thing we need to do is create an instance of XmlTextWriter using its constructor. XmlTextWriter has three overloaded constructors, which can take a string, stream, or a TextWriter as an argument. We'll pass a string (file name) as an argument, which we're going to create in C:\ root.

In my sample example, I create a file myXmlFile.xml in C:\\ root directory. 

After creating an instance, first thing you call us WriterStartDocument. When you're done writing, you call WriteEndDocument and TextWriter's Close method. 

The WriteStartDocument and WriteEndDocument methods open and close a document for writing. You must have to open a document before start writing to it. WriteComment method writes comment to a document. It takes only one string type of argument. WriteString method writes a string to a document. With the help of WriteString, WriteStartElement and WriteEndElement methods pair can be used to write an element to a document. The WriteStartAttribute and WriteEndAttribute pair writes an attribute.

WriteNode is more write method, which writes an XmlReader to a document as a node of the document. For example, you can use WriteProcessingInstruction and WriteDocType methods to write a ProcessingInstruction and DocType items of a document.

The below sample example summarizes all these methods and creates a new xml document with some items in it such as elements, attributes, strings, comments and so on. See Listing 5-14. In this sample example, we create a new xml file c:\xmlWriterText.xml. In this sample example, We create a new xml file c:\xmlWriterTest.xml using XmlTextWriter: 

After that, we add comments and elements to the document using Writexxx methods. After that we read our books.xml xml file using XmlTextReader and add its elements to xmlWriterTest.xml using XmlTextWriter.

About Sample Example 3

In this sample example, I create a new file myxmlFile.xml using XmlTextWriter and use its various write methods to write XML items.

Sample Example 3.  

Using XmlDocument

The XmlDocument class represents an XML document. This class provides similar methods and properties we've discussed earlier in this article.

Load and LoadXml are two useful methods of this class. A Load method loads XML data from a string, stream, TextReader or XmlReader. LoadXml method loads XML document from a specified string. Another useful method of this class is Save. Using Save method you can write XML data to a string, stream, TextWriter or XmlWriter.

About Sample Example 4

This tiny sample example is pretty easy to understand. We call LoadXml method of XmlDocument to load an XML fragment and call Save to save the fragment as an XML file.

Sample Example 4.

You can also use Save method to display contents on console if you pass Console.Out as a parameter. For example:

About Sample Example 5

Here is one example of how to load an XML document using XmlTextReader. In this sample example, we read books.xml file using XmlTextReader and call its Read method. After that we call XmlDocumetn's Load method to load XmlTextReader contents to XmlDocument and call Save method to save the document. Passing Console.Out as a Save method argument displays data on the console

Sample Example 5.

Writing Data from a database to an XML Document

Using XML and ADO.NET mode, reading a database and writing to an XML document and vice versa is not a big deal. In this section of this article, you will see how to read a database table's data and write the contents to an XML document. 

The DataSet class provides method to read a relational database table and write this table to an XML file. You use WriteXml method to write a dataset data to an XML file.

In this sample example, I have used commonly used Northwind database comes with Office 2000 and later versions. You can use any database you want. Only thing you need to do is just chapter the connection string and SELECT SQ L query.

About Sample Example 6

In this sample, I create a data adapter object and selects all records of Customers table. After that I can fill method to fill a dataset from the data adapter.

In this sample example, I have used OldDb data provides. You need to add a reference to the System.Data.OldDb namespace to use OldDb data adapters in your program. As you can see from Sample Example 6, first I create a connection with northwind database using OldDbConnection. After that I create a data adapter object by passing a SELECT SQL query and connection. Once you have a data adapter, you can fill a dataset object using Fill method of the data adapter. Then you can WriteXml method of DataSet, which creates an XML document and write its contents to the XML document. In our sample, we read Customers table records and write DataSet contents to OutputXml.Xml file in C:\ dir.

Sample Example 6.  

.NET Framework Library provides a good support to work with XML documents. The XmlReader, XmlWriter and their derived classes contains methods and properties to read and write XML documents. With the help of the XmlDocument and XmlDataDocument classes, you can read entire document. The Load and Save method of XmlDocument loads a reader or a file and saves document respectively. ADO.NET provides functionality to read a database and write its contents to the XML document using data providers and a DataSet object.

Download Free Book

  • Create XML document with C#
  • Read write XML
  • Reading XML in C#
  • Write XML in C#

C# Corner Ebook

Programming XML with C#

how to write and read xml documents


How to read and write xml files in qt c++.

  • General Programming

How to Read and Write XML files in QT C++

Let's begin.

We can write and read XML files to store some datas in an XML file to use later. In qt we can perform this operations with QtXML library.

  • QtXml will let us to manage the XML operations with QtXml.
  • QTextStream will let us to read and write XML file which store the datas.

Now we let's create XML elements and load datas in it. Then write them into file.

What have we done in writing method :

  • Firstly we controlled the XML file and if there is no problem we opened than set it to xmlContent .
  • Then we create an XML document with QDomDocument . We are going to create nodes under this document.
  • Then we created our root element with QDomElement . We appended root element to our document. Because we want our root element directly under the document.
  • Then we created other elements under root element. For appending sub nodes to root node we used root.appendChild(...); method.
  • Lastly we wrote all XML data inside an XML file with xmlContent << document.toString(). We created xmlContent variable at the head of method with a QTextStream.

XML Writing example output - Thecodeprogram

Now let's read the XML file which we have written above.

What have we done in reading method :

  • Firstly we read the related XML file and loaded into QDomDocument to parse content data.
  • Then we created QDomElement and readed first child node. In here we assumed there is only one root node and all sub nodes inside this root node.
  • Then we started to read nodes inside root node. We set the tag name as student and we assigned related datas into attributes to. (I like to use attributes instead of sub nodes if not necessary)
  • In while loop we are traversing all of nodes until find the null one. It means we traverse all nodes.
  • And lastly I showed the datas inside a textbox.

XML Reading XML file in QT C++ - Thecodeprogram

That is all in this article.

Have a good XML management.

Burak Hamdi TUFAN

Share this Post

Burak Hamdi TUFAN

I am a software developer experienced 15 years and here to share all my programming experiences. I have worked on so many platforms and programming languages especially C, C#, C++ and Java. I am studing PhD at Kocaeli University on Aviation Technologies. I am building softwares and technologies on aviation.

FROM : General Programming

How to use Interop Services in C# (Focus on external window)

How to use Interop Services in C# (Focus on external window)

Java ile Multithreading

Java ile Multithreading

Java'da Threadlerin Çalışması Esnasındaki Durumları

Java'da Threadlerin Çalışması Esnasındaki Durumları

Post a comment.

  • There is no comment. Be the owner of first comment...


Python XML File – How to Read, Write & Parse

Steve Campbell

What is XML?

XML stands for eXtensible Markup Language. It was designed to store and transport small to medium amounts of data and is widely used for sharing structured information.

Python enables you to parse and modify XML documents. In order to parse XML document, you need to have the entire XML document in memory. In this tutorial, we will see how we can use XML minidom class in Python to load and parse XML files.

How to Parse XML using minidom

We have created a sample XML file that we are going to parse.

Step 1) Create Sample XML file

Inside the file, we can see the first name, last name, home, and the area of expertise (SQL, Python, Testing and Business)

How to Parse XML using minidom

Step 2) Use the parse function to load and parse the XML file

Once we have parsed the document, we will print out the “node name” of the root of the document and the “ firstchild tagname” . Tagname and nodename are the standard properties of the XML file.

Parse XML using minidom

  • Import the xml.dom.minidom module and declare file that has to be parsed (myxml.xml)
  • This file carries some basic information about an employee like first name, last name, home, expertise, etc.
  • We use the parse function on the XML minidom to load and parse the XML file
  • We have variable doc and doc gets the result of the parse function
  • We want to print the nodename and child tagname from the file, so we declare it in print function
  • Run the code- It prints out the nodename (#document) from the XML file and the first child tagname (employee) from the XML file

Nodename and child tagname are the standard names or properties of an XML dom.

Step 3) Call the list of XML tags from the XML document and printed out

Next, We can also call the list of XML tags from the XML document and printed out. Here we printed out the set of skills like SQL, Python, Testing and Business.

Parse XML using minidom

  • Declare the variable expertise, from which we going to extract all the expertise name employee is having
  • Use the dom standard function called “getElementsByTagName”
  • This will get all the elements named skill
  • Declare loop over each one of the skill tags
  • Run the code- It will give list of four skills

How to Write XML Node

We can create a new attribute by using the “createElement” function and then append this new attribute or tag to the existing XML tags. We added a new tag “BigData” in our XML file.

  • You have to code to add the new attribute (BigData) to the existing XML tag
  • Then, you have to print out the XML tag with new attributes appended with the existing XML tag

Write XML Node

  • To add a new XML and add it to the document, we use code “doc.create elements”
  • This code will create a new skill tag for our new attribute “Big-data”
  • Add this skill tag into the document first child (employee)
  • Run the code- the new tag “big data” will appear with the other list of expertise

XML Parser Example

Python 2 Example

Python 3 Example

How to Parse XML using ElementTree

ElementTree is an API for manipulating XML. ElementTree is the easy way to process XML files.

We are using the following XML document as the sample data:

Reading XML using ElementTree:

we must first import the xml.etree.ElementTree module.

Now let’s fetch the root element:

Following is the complete code for reading above xml data

Python enables you to parse the entire XML document at one go and not just one line at a time. In order to parse XML document you need to have the entire document in memory.

  • To parse XML document
  • Import xml.dom.minidom
  • Use the function “parse” to parse the document ( doc=xml.dom.minidom.parse (file name);
  • Call the list of XML tags from the XML document using code (=doc.getElementsByTagName( “name of xml tags”)
  • To create and add new attribute in XML document
  • Use function “createElement”
  • Online Python Compiler (Editor / Interpreter / IDE) to Run Code
  • PyUnit Tutorial: Python Unit Testing Framework (with Example)
  • How to Install Python on Windows [Pycharm IDE]
  • Hello World: Create your First Python Program
  • Python Variables: How to Define/Declare String Variable Types

Book cover

Beginning xml with C# 2008 pp 61–89 Cite as

Reading and Writing XML Documents

557 Accesses

Chapter 2 gave you a detailed understanding of the .NET Framework's DOM parser, that is, the XmlDocument class. You also learned when to use DOM parsers. In this chapter, you are going to learn about XML reader and writer classes. The topics discussed include the following:

Using reader and writer classes

Knowing when to use these classes instead of DOM

Reading XML documents by using the XmlTextReader class

Writing XML documents by using the XmlTextWriter class

Working with a subset of XML documents and reader and writer classes

This is a preview of subscription content, access via your institution .

Buying options

  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Unable to display preview.  Download preview PDF.

Rights and permissions

Reprints and Permissions

Copyright information

© 2008 Bipin Joshi

About this chapter

Cite this chapter.

(2008). Reading and Writing XML Documents. In: Beginning xml with C# 2008. Apress. https://doi.org/10.1007/978-1-4302-0998-0_3

Download citation

DOI : https://doi.org/10.1007/978-1-4302-0998-0_3

Publisher Name : Apress

Print ISBN : 978-1-4302-0997-3

Online ISBN : 978-1-4302-0998-0

eBook Packages : Professional and Applied Computing Professional and Applied Computing (R0) Apress Access Books

Share this chapter

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Find a journal
  • Publish with us

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Reading and Writing XML Schemas

  • 12 contributors

The Schema Object Model (SOM) API can be used to read and write XML Schema definition language (XSD) schemas from files or other sources and build XML schemas in-memory using the classes in the System.Xml.Schema namespace that map to the structures defined in the World Wide Web Consortium (W3C) XML Schema Recommendation.

The XmlSchema class provides the Read and Write methods to read and write XML schemas. The Read method returns an XmlSchema object representing the XML schema and takes an optional ValidationEventHandler as a parameter to handle schema validation warnings and errors encountered while reading an XML schema.

The Write method writes XML schemas to Stream , TextWriter and XmlWriter objects and can take an optional XmlNamespaceManager object as a parameter. An XmlNamespaceManager is used to handle namespaces encountered in an XML schema. For more information about the XmlNamespaceManager class, see Managing Namespaces in an XML Document .

The following code example illustrates reading and writing XML schemas from and to a file. The code example takes the example.xsd file, reads it into an XmlSchema object using the static Read method, and then writes the file to the console and a new new.xsd file. The code example also provides a ValidationEventHandler as a parameter to the static Read method to handle any schema validation warnings or errors encountered while reading the XML schema. If the ValidationEventHandler is not specified ( null ), no warnings or errors are reported.

The example takes the example.xsd as input.

  • XML Schema Object Model Overview
  • Building XML Schemas
  • Traversing XML Schemas
  • Editing XML Schemas
  • Including or Importing XML Schemas
  • XmlSchemaSet for Schema Compilation
  • Post-Schema Compilation Infoset
  • Managing Namespaces in an XML Document

Submit and view feedback for

Additional resources


  1. java

    how to write and read xml documents

  2. An example of XML document

    how to write and read xml documents

  3. How to write XML data/ XML file with the help of PHP

    how to write and read xml documents

  4. Sample XML document for sharing with Crawler

    how to write and read xml documents

  5. XML basics

    how to write and read xml documents

  6. Read a XML File C#, Reading XML with XmlReader, Parse an XML file, read Data from Xml file in c#

    how to write and read xml documents



  2. Present XMl in comment

  3. How To Write Design Docs

  4. How To Make Add Data By Xml

  5. 𝙲𝚘𝚙𝚒𝚍 𝚎𝚗𝚐𝚕𝚒𝚜𝚑 𝚜𝚘𝚗𝚐𝚜//description link 🔰⬇️✅ xml file 📂👇

  6. lec1 part4 (XML example,XML syntax)


  1. How to Find the Right Template to Write a Document for Free

    Writing documents can be a daunting task, especially if you’re not sure where to start. Fortunately, there are many free templates available online that can help you get started. Here are some tips on how to find the right template to write...

  2. How Do You Write a Reading Log?

    To write a reading log, note the title and author of the book, the numbers of the pages read, a brief summary and a response. It is helpful to write notes for the reading log while you are reading. You need the book you are reading and a no...

  3. How Do Someone Write a Scoping Document?

    A scoping document can be written by writing about the project including justification, product, deliverables and objectives. A scoping document is important for project managers because it helps them by guiding them towards making intellig...

  4. Reading and Writing XML Files in Python

    Then passed the filename of the xml file to the ElementTree.parse() method, to enable parsing of our xml file. Then got the root (parent tag) of

  5. How to Read and Write XML Files With Code

    Let us look at the basic steps required for reading an XML file using the DOM API. The first step is to get an instance of DocumentBuilder. The

  6. java

    6 Answers 6 ; new ArrayList<String>(); Document dom; // Make an instance of the DocumentBuilderFactory ; // XML file dom = db.parse(xml); Element

  7. XML Files: What They Are & How to Open Them

    person using a computer to read and edit an XML file. Cue XML, one of the ... xml file example storing names and test scores of students-1.

  8. Reading and writing XML documents

    Data exchange > Understanding data exchange > Reading and writing XML documents. NEW! COVID-19 Community response · Hello, 1C.

  9. How to Read XML File in Java

    The DOM API provides the classes to read and write an XML file. We can create, delete, modify, and rearrange the node using the DOM API.

  10. Reading and Writing XML in C#

    The XmlReader, XmlWriter and their derived classes contains methods and properties to read and write XML documents. With the help of the

  11. How to Read and Write XML files in QT C++

    Firstly we read the related XML file and loaded into QDomDocument to parse content data. · Then we created QDomElement and readed first child node. · Then we

  12. Python XML File

    Step 1) Create Sample XML file · Step 2) Use the parse function to load and parse the XML file · Step 3) Call the list of XML tags from the XML

  13. Reading and Writing XML Documents

    Just as XmlReader allows you to read XML documents, a class called XmlWriter allows you to write XML documents. Like XmlReader, XmlWriter also uses a

  14. Reading and Writing XML Schemas

    Read and write XML Schema definition language (XSD) schemas from files or other sources in .NET, using the Schema Object Model (SOM) API.