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
27
votes
3 answers

Importance of indenting XML file

Is it necessary to indent the XML tags in a XML file for successful parsing of the file?
Abhinav
  • 992
  • 2
  • 11
  • 26
27
votes
2 answers

DOMDocument getNodeValue() returns null (contains an output escaped string)

I am processing a DomDocument which is basically the XML result of a SOAP web service. To give you an idea, this is what it looks like ...<output><escaped<string... Yes, the value of…
user1020069
  • 1,540
  • 7
  • 24
  • 41
27
votes
5 answers

Spring "The prefix "tx" for element "tx:annotation-driven" is not bound."

I'm getting the error above on my "tx:annotation-driven" line, but I've declared the namespace at the top of the beans file, why is the following XML causing this error?
David
  • 19,577
  • 28
  • 108
  • 128
27
votes
11 answers

Check well-formed XML without a try/catch?

Does anyone know how I can check if a string contains well-formed XML without using something like XmlDocument.LoadXml() in a try/catch block? I've got input that may or may not be XML, and I want code that recognises that input may not be XML…
Steve Cooper
  • 20,542
  • 15
  • 71
  • 88
27
votes
6 answers

SharedPreferences value is not updated

I am trying to update the values of SharedPreferences, here is my code: edit =…
Juned
  • 6,290
  • 7
  • 45
  • 93
27
votes
1 answer

XPath count() function

Suppose I have an XML tree as below: proceedings -name -contents -article -author -title -pages How can I identify any title that has only one author? And the number of articles that have more than three…
emen
  • 6,050
  • 11
  • 57
  • 94
26
votes
4 answers

How to change character encoding of XmlReader

I have a simple XmlReader: XmlReader r = XmlReader.Create(fileName); while (r.Read()) { Console.WriteLine(r.Value); } The problem is, the Xml file has ISO-8859-9 characters in it, which makes XmlReader throw "Invalid character in the given…
dstr
  • 8,362
  • 12
  • 66
  • 106
26
votes
7 answers

Can we force XmlWriter to issue rather than ?

By default, someXmlWriter.WriteElementString("my-tag", someString); produces I looked around XmlWriterSettings class for possible options that would force the writer to produce instead but didn't find anything. Is…
mjv
  • 73,152
  • 14
  • 113
  • 156
26
votes
10 answers

Why is JSON important?

I've only recently heard about JSON (Javascript Object Notation). Can anybody explain why it is considered (by some websites/blogs/etc) to be important? We already have XML, why is JSON better (apart from being 'native to Javascript')? Edit: Hmm,…
Rabarberski
  • 23,854
  • 21
  • 74
  • 96
26
votes
2 answers

Android using layouts as a template for creating multiple layout instances

OK, So I understand how to use the include tag but I've run into a problem. Basically I want to have a layout defined in xml which has a couple of TextViews and an ImageView in it. I then want to iterate across an array and populate fields within…
gunboatmedia
  • 435
  • 1
  • 6
  • 15
26
votes
4 answers

Simplify/ Clean up XML of a DOCX word document

I have a Microsoft Word Document (docx) and I use Open XML SDK 2.0 Productivity Tool to generate C# code from it. I want to programmatically insert some database values to the document. For this I typed in simple text like [[place holder 1]] in the…
K B
  • 1,330
  • 1
  • 18
  • 30
26
votes
3 answers

How do I select a top-level attribute of an XML column in SQL Server?

I have an XML column in SQL Server that is the equivalent of: I want to get the value of the foo attribute of Test (the root element) as a varchar. My goal would be something along the lines…
Alex Argo
  • 8,920
  • 12
  • 43
  • 46
26
votes
2 answers

Access @attributes data in SimpleXMLElement in PHP

Just wanted to start by saying I have read a LOT of the questions on this site about this exact problem, but I'm still struggling to apply it to my scenario. If someone could help me out, that'd be great! :) I am trying to extract data from the…
John Cleary
  • 263
  • 1
  • 3
  • 4
26
votes
2 answers

What is the difference between   and  ?

I have written one XSLT to transform xml to html. If input xml node contains only space then it inserts the space using following code.   There is another numeric character which also does same thing as shown…
Sambhaji
  • 990
  • 5
  • 19
  • 31
26
votes
5 answers

Spring v3 no declaration can be found for element 'mvc:resources'

Currently Running Tomcat: v6 Spring Tools Suite: v2.7.2 Spring Framework: spring-webmvc-3.0.5 Servlet XML
Luc Laverdure
  • 1,398
  • 2
  • 19
  • 36