Skip to main content

XML - 2

(XML Tree)

Example:

DOM node tree

The image above represents one book in the XML below:



Everyday Italian
Giada De Laurentiis
2005
30.00


Harry Potter
J K. Rowling
2005
29.99


Learning XML
Erik T. Ray
2003
39.95

The root element in the example is . All elements in the document are contained within .

The element has 4 children: ,<>, , .

----------------------------------------------------------------

XML Tags are Case Sensitive

  • Entity References

Some characters have a special meaning in XML.

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.

This will generate an XML error:

if salary <>

To avoid this error, replace the "<" character with an entity reference:

if salary < 1000 then

There are 5 predefined entity references in XML:

< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.

--------------------------

XML Naming Rules

XML elements must follow these naming rules:

  • Names can contain letters, numbers, and other characters
  • Names cannot start with a number or punctuation character
  • Names cannot start with the letters xml (or XML, or Xml, etc)
  • Names cannot contain spaces

Any name can be used, no words are reserved.

---------------------------------------

XML Elements are Extensible

XML elements can be extended to carry more information.

Look at the following XML example:


Tove
Jani
Don't forget me this weekend!

Let's imagine that we created an application that extracted the , , and elements from the XML document to produce this output:

MESSAGE

To: Tove
From: Jani

Don't forget me this weekend!

Imagine that the author of the XML document added some extra information to it:


2008-01-10
Tove
Jani
Reminder
Don't forget me this weekend!

Should the application break or crash?

No. The application should still be able to find the , , and elements in the XML document and produce the same output.






Comments

Popular posts from this blog

Backslash on mac

I had been struggling to type back slash ( \) character on mac japanese keyboard as they don't have it printed on the keyboard, and I was doing copy paste all the time from google when i needed to type it until recently a tip came to my rescue , shortcut to backslash on mac japanese keyboard. Alt + ¥  Hope it helps others. 

How to Enter Split View on MAC

Enter Split  View Hover your pointer over the full-screen button in the upper-left corner of a  window . Or click and hold the button. Choose ”Tile  Window  to Left of Screen” or ”Tile  Window  to Right of Screen” from the menu. ... Then click a  window  on the other side of the screen to begin using both  windows  side by side. Hover your pointer over the full-screen button in the upper-left corner of a  window . Or click and hold the button. Choose ”Tile  Window  to Left of Screen” or ”Tile  Window  to Right of Screen” from the menu. ... Then click a  window  on the other side of the screen to begin using both  windows  side by side.