XML Basics

Before making/editing XML, lets first learn what it is. That begins with understanding why XML is; why does it exist? Basically, XML was created to serve as an easily usable, readable method to format information within an basic text file. What it does is allows you to contain information (text/numbers) in a hierarchal manner. This means one bit of information can serve as a type of file folder for holding more information.

In fact, you can think of XML just as that, as a text write-out of a hierarchical file system. It is NOT a script and does NOT "do" anything. It just provides information in an outlined and logically laid out manner.

For more information beyond laymens terms, see:
http://www.xml.com/
http://www.w3.org/XML/


XML structure
Looking at XML, you'll notice it looks a lot like HTML. In a way, HTML is a type of XML (though it was around before XML was) but the structure is in many cases the same. Here's a simple example of an XML file:

<LETTER>
 <TO>Sandy</TO>
 <FROM>Joseph</FROM>
 <BODY>I love you!</BODY>
</LETTER>

Its fairly easy to see what information this XML file holds and how its laid out. In the file folder metaphor, this represents a folder called LETTER which contains 3 other folders TO, FROM and BODY. Each one of those folders contains the given text. The folder TO for example has "Sandy" in it.

The XML itself is made up primarily of 2 things, Nodes and Attributes. Each one of these are containers for information, though attributes are special in that they are contained only within nodes. In the example above, each one of the 'folders' (ie LETTER, TO, etc.) are a node. Nodes, as the name suggests, are containers which can hold textual information (in Attributes) as well as have within them other nodes as seen above. Its this encapsulation which makes up the hierarchy of a XML file defining its structure.

There are no attributes in the LETTER XML example, and often attributes aren't used at all. However, they can be useful in specifying properties or little tid-bits of information within a given node. Here is an example that uses attributes:

<THURSDAY>
 <MEETING TIME="10:00">
  The meeting was boring. I made paper airplanes with a memo I recieved earlier.
 </MEETING>
 <LUNCH TIME="1:30">
  John came over to talk to me.  He smells funny today.
  <SERVED MAINCOURSE="Steak" SIDE1="Apple" SIDE2="Mustard" DRINK="TANG" />
  <SPENT MEALCARD="0" CASH="12.00" />
 </LUNCH>
</THURSDAY>

MEETING, for example, contains the attribute TIME. TIME's value is 10:00. In HTML attributes would be like the href or target options within an anchor <a></a> tag. TIME just gives you a way to specify some extra information which is associated directly with that node.

The above example demonstrates two other things:

  1. Nodes with out any child nodes, or nodes within it, can be terminated within their own tag using /> instead of re-writing the tag over again in closing tag. For example, <NODE1></NODE1> can be instead be written as <NODE1/>. This is seen with the SERVED and SPENT nodes within LUNCH.
     

  2. You can see how the text in the LUNCH node - "John came over to talk to me. He smells funny today." - sits pleasantly with the other nodes SERVED and SPENT. This is because that text is itself a node. Its a text node. It doesn't have any bracket tags nor any attributes or child nodes (folders in itself). All it is is just text - its a text node! The first example also had text nodes. "Sandy", "Joseph" and "I love you!" were all text nodes. Non-text nodes can also be referred to as "Elements".

Hopefully, for those of you who didn't know anything or knew little about XML, this cleared some things up or gave you an idea on how to perceive XML. Feel free to post any questions you may have on the forums.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值