<< Chapter < Page Chapter >> Page >
This module describes XML (eXtensible Markup Language) and the rules that govern its usage. It also explains what a well-formed and valid document is.

What is xml?

The eXtensible Markup Language ( XML ) is a meta-markup language defined by the World Wide Web Consortium (W3C) . It is not strictly a markup language itself, but rather a set of rules for creating markup languages. Forour purposes a markup language is any language (HTML, for example) that uses tags surrounding text to conveyinformation such as content or format. CNXML , the markup language used by the Connexions Project is an example of a language written in XML. There are many otherexamples at the W3C site. Here is an example of some markup in CNXML.

<para>This is a paragraph in<term>CNXML</term>. Notice that the markup contains tags that express the meaning of the text.</para>
Got questions? Get instant answers now!

<para> and </para> are the tags that enclose the text. In XML, tags are always marked by anglebrackets (also known as < and > ). Tags generally come in pairs. An opening tag will look like <tagname> . A closing tag will look like </tagname> , with a / preceding the tag name.

XML allows the separation of presentation from content. For example, HTML has tags such as <u> and <i> , which underline and italicize text respectively. This does not express content information,only formatting. XML allows you to define your own language of tags to represent content. You could create a tag called <book> to represent book titles, and create a stylesheet (a separate formatting document), thatsays that every <book> tag should be italicized or underlined. Then when you want to change thepresentation of that type of content, you just change one small part of the stylesheet. Also, if you make tags thatconvey the content of the document, you can enable better searching. For example, you might look for the author of a document by looking at the author tag.

Well-formed xml

XML has a few rules that apply to all of its languages, including CNXML. If a document satisfies theserules, then it is well-formed . XML documents are required to be well-formed.

  • Every tag that is opened must be closed. An opening tag looks like <module> and a closing tag looks like </module> . There is a shortcut. If your tag contains no other tags (referred toas an empty tag ), then you can can type a / before the end of the opening tag and delete the closingtag. For example, <media></media> can be abbreviated <media/> .
  • Tags must be nested within each other. So, <b>red<i>and</i>blue</b> is fine, but <b>red<i>and</b>blue</i> is incorrect because the <b> and <i> tags have overlapping content.
  • You must put either single or double quotes around an attribute value. An attribute is some sort of information that is associated with a tag and is listedinside of the tag itself. For example, <module id="m0001"> and <module id='m0001'> are fine, but <module id=m0001> is incorrect.
  • You can also choose to start every document with an XML declaration . If you do use the XML declaration, then it has to be the very first thing in thefile. It cannot even be preceded by whitespace. It is not considered to be a tag. The XML declaration is asfollows. <?xml version="1.0"?> You can also include other information such as the encoding of the document or whether the document dependson other files or not.
  • There must be one tag that contains all of the other tags. For example in xhtml <html> and </html> must surround all of the other tags. There are some things that are includedat the top of the document that are not tags and that are not included with the tags. The XML declaration is anexample of this.

Valid xml

It is possible to define a set of rules that apply to all of the tags in a particular XML language. These rules can bedefined in a couple of different ways. The most common way is to use a DTD (Document Type Definition). Any document which follows all of the rules for that language iscalled valid . A document is not required to be valid in order to be XML. However, it is generally a goodidea.

Entity references

Entity references in cnxml 0.6

Entity references are no longer supported by CNXML 0.6. Instead, we suggest that you use character references as described below to add special characters to your module.

XML uses several characters in special ways as part of its markup, in particular the less-than symbol ( < ), the greater-than symbol ( > ), the double quotation mark ( " ), the apostrophe ( ' ), and the ampersand ( & ). You've already seen examples of markup using the first four of those previously in this module.But what if you need to these characters in your content, and you don't want them to be treated as part of the markup by XML processors? You can use XML entity references for this purpose. The XML Specification defines the following five entity references for use in any well-formed XML document:

  • &amp; refers to an ampersand (&)
  • &lt; refers to a less-than symbol (<)
  • &gt; refers to a greater-than symbol (>)
  • &quot; refers to a double-quote mark (")
  • &apos; refers to an apostrophe (')

Suppose you have a document with the following: <para id="p1">The firm was known as Scrooge and Marley.</para> you could replace 'and' with the entity reference &amp; : <para id="p1">The firm was known as Scrooge&amp; Marley.</para>

Got questions? Get instant answers now!

All entity references outside the above five must be defined in a document type declaration, and they may only be used in documents that conform to that DTD. Note that an entity reference always begins with & and ends with ; .

Character references

You can also use any character defined in Unicode in an XML document by means of character references . Unicode is a project to define a unique code for everycharacter in any human language. Unicode is very useful any time that you need to use a symbol that is not a part ofASCII.

Character references in XML either begin with &# , or they begin with &#x , and they end with a semicolon ; . A character reference contains a representation of a Unicode code point: if it begins with &# , then it contains a decimal representation of a Unicode code point; if it begins with &#x , then it contains a hexidecimal representation of a Unicode code point.

The hexidecimal representation of the Unicode code point for the small 'o' with a stroke is 00F8 , and the decimal representation for the same is 248 . Therefore, the character references for the small 'o' with a stroke are &#x00F8; and &#248; So you could write <emphasis>The majestik m&#x00F8;&#x00F8;se</emphasis> or <emphasis>The majestik m&#248;&#248;se</emphasis> or even <emphasis>The majestik m&#x00F8;&#248;se</emphasis> to get

The majestik møøse

Got questions? Get instant answers now!

Questions & Answers

A golfer on a fairway is 70 m away from the green, which sits below the level of the fairway by 20 m. If the golfer hits the ball at an angle of 40° with an initial speed of 20 m/s, how close to the green does she come?
Aislinn Reply
cm
tijani
what is titration
John Reply
what is physics
Siyaka Reply
A mouse of mass 200 g falls 100 m down a vertical mine shaft and lands at the bottom with a speed of 8.0 m/s. During its fall, how much work is done on the mouse by air resistance
Jude Reply
Can you compute that for me. Ty
Jude
what is the dimension formula of energy?
David Reply
what is viscosity?
David
what is inorganic
emma Reply
what is chemistry
Youesf Reply
what is inorganic
emma
Chemistry is a branch of science that deals with the study of matter,it composition,it structure and the changes it undergoes
Adjei
please, I'm a physics student and I need help in physics
Adjanou
chemistry could also be understood like the sexual attraction/repulsion of the male and female elements. the reaction varies depending on the energy differences of each given gender. + masculine -female.
Pedro
A ball is thrown straight up.it passes a 2.0m high window 7.50 m off the ground on it path up and takes 1.30 s to go past the window.what was the ball initial velocity
Krampah Reply
2. A sled plus passenger with total mass 50 kg is pulled 20 m across the snow (0.20) at constant velocity by a force directed 25° above the horizontal. Calculate (a) the work of the applied force, (b) the work of friction, and (c) the total work.
Sahid Reply
you have been hired as an espert witness in a court case involving an automobile accident. the accident involved car A of mass 1500kg which crashed into stationary car B of mass 1100kg. the driver of car A applied his brakes 15 m before he skidded and crashed into car B. after the collision, car A s
Samuel Reply
can someone explain to me, an ignorant high school student, why the trend of the graph doesn't follow the fact that the higher frequency a sound wave is, the more power it is, hence, making me think the phons output would follow this general trend?
Joseph Reply
Nevermind i just realied that the graph is the phons output for a person with normal hearing and not just the phons output of the sound waves power, I should read the entire thing next time
Joseph
Follow up question, does anyone know where I can find a graph that accuretly depicts the actual relative "power" output of sound over its frequency instead of just humans hearing
Joseph
"Generation of electrical energy from sound energy | IEEE Conference Publication | IEEE Xplore" ***ieeexplore.ieee.org/document/7150687?reload=true
Ryan
what's motion
Maurice Reply
what are the types of wave
Maurice
answer
Magreth
progressive wave
Magreth
hello friend how are you
Muhammad Reply
fine, how about you?
Mohammed
hi
Mujahid
A string is 3.00 m long with a mass of 5.00 g. The string is held taut with a tension of 500.00 N applied to the string. A pulse is sent down the string. How long does it take the pulse to travel the 3.00 m of the string?
yasuo Reply
Who can show me the full solution in this problem?
Reofrir Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Connexions tutorial and reference. OpenStax CNX. Feb 23, 2012 Download for free at http://cnx.org/content/col10151/1.27
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Connexions tutorial and reference' conversation and receive update notifications?

Ask