开发者

How XML used and interpreted?

My understanding is that XML is used to communicate between two applications using user defined tags.

I have done some research and found many tutorials on XML, but not any describing where to use XML.

My understanding is that XML is famous for being user friendly. By this I mean that you can define your own custom tags. But I am wondering where and how those tags are interpreted?

Please point me to resources on where to use XML and how to interpr开发者_如何学编程et the meaning of an XML file, so that I can understand its basics and use it effectively.


Your difficulty in understanding where XML fits into the big picture is a common one.

When you send someone an email message with a Word attachment, there are multiple levels of protocol involved: there's TCP/IP, there's the email protocols, there's the Word document format. But ultimately, your message only means anything to the recipient if they understand English, and understand what you are talking about. Word provides a standard (of kinds) for the format of documents, but for the message to be understood, the sender and recipient still need a common vocabulary for the subject matter of what they want to discuss. XML fits into the same level of the picture as Word - it standardizes the format of the messages, but leaves users free to decide their own vocabularies. There are many vocabularies that have been standardized on top of XML (for financial messages, SVG graphics, music, mathematical formulae, etc, etc) but the strength of XML is that you can use it for any vocabulary you like, while still getting the benefits of a common format and syntax underneath.

But just as you can send a Word document to someone who won't understand it because they don't speak English, so you can send an XML document containing, say XBRL financial data to someone who won't understand it because they don't know the XBRL vocabulary.


XML stands for Extensible Markup Language. It provides a set of rules for structuring and encoding documents in machine readable form.

XML speaks to the syntax of your documents and the relationship between objects in your documents, but little to the semantics or meaning of documents or objects in documents.

The semantics - or as you put it, how they are interpreted - is captured in the code that processes the documents.

Must programming environments provide one or more ways to process - parse - XML content. But as noted above the interpretation is left in the hands of the application once it has been parsed.

For example, the Ruby Programming Language has multiple XML parsers available to it. Two of them are REXML and XmlSimple.

Remember, an XML parser helps you with the syntax of the document, but meaning comes from your code and how you interpret the content and structure of the document.

For example, the following document could represent a lot of things, but my code would interpret it as being a configuration file that specifies the a set of servers, their os, os version, and IP addresses.

<config logdir="/var/log/foo/" debugfile="/tmp/foo.debug">
    <server name="sahara" osname="solaris" osversion="2.6">
      <address>10.0.0.101</address>
      <address>10.0.1.101</address>
    </server>
    <server name="gobi" osname="irix" osversion="6.5">
      <address>10.0.0.102</address>
    </server>
    <server name="kalahari" osname="linux" osversion="2.0.34">
      <address>10.0.0.103</address>
      <address>10.0.1.103</address>
    </server>
  </config>


As you say, we use XML to pass data between applications, often those applications are written in different programming languages, and so XML gives us a common data format.

When we get into the applciation code itself it's most convenient to work with the langauges natural constructs. For example:

<Order>
       <Customer name="bill" phone="123-345456" >   
       etc.       
</Order>

In some environments (for example in Enterprise Service Bus products) you actual work with the XML, defining transformations of the XML. So you could google for various ESB products and read about them.I work for IBM and Sos I'm familiar with WebSphere ESB and quite interestingly there are hardware XML processing products, for example IBM's DataPower, which can really speed up XML processing.

But in usual programming languages it's very convenient to write your application code against programming constructs representing the data, so in Java we'd like an Order class, and a Customer class and so on.

Then having converted the XML to objects we can just write natural code such as

 customer.getName()

So different programming environment will have different appraoches to dealing with these kind of conversions. In the Java world there have been several approaches to this mapping between XML and Java. These days JAX/B is increasingly used, I have a brief example in this article where you will see there is very little code to write to perform the conversion.


Your Question sounds like you are comparing XML to html and wonder how a browser can guess the meaning of self defined tags. In fact it can't. You have to write a translation script in XSLT and connect this to your XML file (e.g. XML Outputting - PHP vs JS vs Anything Else?). Of course XML is not a tool for only adding a translation step. Im this case it's to be used when you want to built HTML pages out of raw data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜