XML Tutorial/Introduction/Introduction — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:26, 26 мая 2010

Elements, Attributes, and Values

   <source lang="xml">

XML uses the same building blocks that HTML does: elements, attributes, and values. An XML element is the most basic unit of your document. An XML element can contain other elements and text. An element has an opening tag with a name ( written between < and > ) and sometimes attributes. The name should describe the element"s purpose. XML is self-describing <name>

   <first>Bond</first> 
   <last>James</last> 

</name> Hierarchies in XML <name>

   <first>Bond</first>
   <middle>JK</middle>
   <last>James</last>

</name> <name> is parent of <first>, <middle> and <last>. <first>, <middle> and <last> are sibling. Text is a child of the element. The text Bond is a child of <first>.

<name>

   <first>Bond</first>
   <middle>JK</middle>
   <last>James</last>

</name>

<name> element has only other elements, and not text, then it is said to have element content. <first>, <middle>, and <last> have only text as children, they are said to have simple content.

Elements can contain both text and other elements(mixed content) <doc>

   <parent>this is some text in my element</parent> 

</doc>

<parent>has three children: A text child containing the text "this is some" and an child. Another text child containing the text inmyelement.</source>


Text content

   <source lang="xml">

<name>

   <first>Bond</first>
   <middle>JK</middle>
   <last>James</last>

</name> Data from the beginning of a start-tag to the end of an end-tag is called an element. <first>is a start-tag </first>is an end-tag <first>John</first>is an element The text between the start-tag and end-tag of an element is called the element content. If the content is just data, not other elements, the element content is referred to as parsed character data, or PCDATA. PCDATA is also referred as with "text content" or "text node." You can include a space before the closing > of a tag <name>

   <first >Bond</first >
   <middle>JK</middle>
   <last>James</last>

</name> or <name> <first >Bond</first > <middle>JK</middle> <last>James</last> </name> You cannot put a space after the opening < character in a tag, or the / character in an end-tag Therefore, the following is not proper XML syntax: < first >Bond< /first > Neither is this: < first >Bond< / first ></source>