Questions tagged [xml]

XML (Extensible Markup Language) is a structured document format defining text encoding rules. When using this tag include additional tags such as programming language, tool sets, XML technologies being used, and other tags describing the environment of the problem posted. XML flexibility lends to a wide variety of uses for human and machine data transfer so be specific as to tools and libraries.

Extensible Markup Language

Wikipedia defines XML as follows:

XML (Extensible Markup Language) is a set of rules for encoding documents in both human-readable and machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards.

Extensible - XML is extensible. It lets you define your own tags.

Markup - The most attractive feature of XML has to be its ability to allow its user to create their own tags. The tags that can be created will be similar to tags in HTML. But with XML you are afforded the opportunity to define your own tags.

Language - XML is a language that is very similar to HTML. But it’s much more flexible because it allows creating custom tags. In this way XML acts like a meta-language: a language that allows us to create or define other languages. For example, with XML we can create other languages, such as RSS.

In short, XML:

  • is designed to transport and store data
  • is a flexible and simpler text format derived from SGML (ISO 8879)
  • is a markup language much like HTML
  • was designed to be self-descriptive
  • stands for eXtensible Markup Language
  • is a W3C Recommendation
  • does not DO anything
  • is just information wrapped in tags

The design goals of XML emphasize simplicity, generality, and usability over the Internet. It is a textual data format with strong support via Unicode for the languages of the world. Although the design of XML focuses on documents, it is widely used for the representation of arbitrary data structures – for example in web services, configuration/settings, and GUI, workflow, and task definition.

XML is also used in some protocols for distributed computing and web services such as SOAP and HTML-RPC and REST (see also SOAP vs REST (differences) )

Many application programming interfaces (APIs) have been developed to aid software developers with processing XML data, and several schema languages exist to aid in the definition of XML-based languages. Schemas are usually defined with an external namespace, but XML also allows you to define tags within the document itself.

XML was introduced in 1996 as version 1.0 and has reached version 1.1 in 2004 which has some unique features but isn't very widely spread.

Structure

As already stated, the structure of XML is very similar to the structure of HTML. That is, an XML document is a tree structure with the nodes being called tags (similar to HTML elements), and if tag T2 is descendant of tag T1, then T2 is inside T1.

XML Technologies

  • XQuery (the XML Query language) is a language for querying XML documents much like querying relational databases.
  • XPath (the XML Path language) is a language for finding information in an XML document; it is a subset of XQuery.
  • XSLT (eXtensible Stylesheet Language Transformations) is used to transform XML documents.
  • XLink (the XML Linking language) defines methods for creating links within XML documents.
  • XPointer (the XML Pointer language) allows hyperlinks to point to specific parts (fragments) of XML documents.

XML versions

There are currently two versions of XML in use.

XML 1.0 is the original version of XML.

XML 1.1 is currently the newest version. Notable changes from XML 1.0 include:

  • XML 1.0 is forward compatible with the Unicode standard.

  • More freedom with using line breaks.

  • Support for additional control characters.

Example Document

The following text is defined using XHTML and entity references; the text serves as an example of XML syntax and structure:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [
  <!ENTITY hello "Hello, World!">
]>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>&hello;</title>
  </head>
  <body>
    <div>&hello;</div>
  </body>
</html>

Resources

The following links provide additional information to learn about XML:

Related Tags

213775 questions
592
votes
7 answers

XDocument or XmlDocument

I am now learning XmlDocument but I've just ran into XDocument and when I try to search the difference or benefits of them I can't find something useful, could you please tell me why you would use one over another ?
Tarik
  • 79,711
  • 83
  • 236
  • 349
588
votes
5 answers

What's the difference between text/xml vs application/xml for webservice response

This is more of a general question about the difference between text/xml and application/xml. I am fairly new to writing webservices (REST - Jersey). I have been producing application/xml since it is what shows up in most tutorials / code examples…
Mike
  • 8,137
  • 6
  • 28
  • 46
534
votes
16 answers

How to Deserialize XML document

How do I Deserialize this XML document: 1020 Nissan Sentra 1010
Alex
  • 39,265
  • 21
  • 45
  • 42
526
votes
27 answers

Pretty printing XML in Python

What is the best way (or are the various ways) to pretty print XML in Python?
Hortitude
  • 13,638
  • 16
  • 58
  • 72
497
votes
34 answers

How to pretty print XML from Java?

I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this? String unformattedXml = "hello"; String formattedXml = new…
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
494
votes
6 answers

What does "xmlns" in XML mean?

I saw the following line in an XML file: xmlns:android="http://schemas.android.com/apk/res/android" I have also seen xmlns in many other XML files that I've come across. What is it?
user88637
  • 11,790
  • 9
  • 37
  • 36
491
votes
12 answers

How does one parse XML files?

Is there a simple method of parsing XML files in C#? If so, what?
domoaringatoo
  • 5,423
  • 3
  • 20
  • 13
489
votes
6 answers

Declaring a custom android UI element using XML

How do I declare an Android UI element using XML?
Casebash
  • 114,675
  • 90
  • 247
  • 350
460
votes
19 answers

How to handle button clicks using the XML onClick within Fragments

Pre-Honeycomb (Android 3), each Activity was registered to handle button clicks via the onClick tag in a Layout's XML: android:onClick="myClickMethod" Within that method you can use view.getId() and a switch statement to do the button logic. With…
smith324
  • 13,020
  • 9
  • 37
  • 58
457
votes
9 answers

How can I build XML in C#?

How can I generate valid XML in C#?
Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
456
votes
12 answers

How do I read and parse an XML file in C#?

How do I read and parse an XML file in C#?
Gajendra
  • 4,649
  • 2
  • 17
  • 3
436
votes
13 answers

Web colors in an Android color XML resource file

What do all of the X11/w3c color codes look like in the format of an Android XML resource file? I know this looks a tad ridiculous as a question, but given the votes apparently it's useful and since it clearly does not require an off-site resource…
gssi
  • 5,043
  • 5
  • 23
  • 23
433
votes
8 answers

How can I find an element by CSS class with XPath?

In my webpage, there's a div with a class named Test. How can I find it with XPath?
Strawberry
  • 66,024
  • 56
  • 149
  • 197
426
votes
45 answers

Manifest Merger failed with multiple errors in Android Studio

So, I am a beginner into Android and Java. I just began learning. While I was experimenting with Intent today, I incurred an error. Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple errors, see…
Rohan
  • 4,456
  • 2
  • 11
  • 8
415
votes
12 answers

Can you provide some examples of why it is hard to parse XML and HTML with a regex?

One mistake I see people making over and over again is trying to parse XML or HTML with a regex. Here are a few of the reasons parsing XML and HTML is hard: People want to treat a file as a sequence of lines, but this is…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226