PHP處理XML的例項
XML is a format created in the late 1990s with the goal to be used in applications that need to interchange information in a format that is human-readable and is independent operating systems on which the applications run. XML was like HTML, which everybody was aware, but imposes more strict structure rules.
Many data formats were created around XML. However, XML is still a pain to write manually. Personally, one of the things I find more painful is to have to write every tag name twice: one for opening a tag and another for closing the tag.
A few years ago there was an attempt to define a new specification for the eventual XML 2.0. That attempt seems to have died. I recall that I proposed to allow tags to have a short close notation to avoid repeating the tag name. It would be like this:
data
The proposal was rejected. It seems that the organizers had no interest in avoiding one of the XML pain points. Given that, I am not surprised if XML 2.0 is really dead.
Nowadays, developers tend to use simpler formats like YAML and JSON to exchange data in a human-readable format. Ten years ago they would have used XML instead.
Many data formats were created around XML. However, XML is still a pain to write manually. Personally, one of the things I find more painful is to have to write every tag name twice: one for opening a tag and another for closing the tag.
A few years ago there was an attempt to define a new specification for the eventual XML 2.0. That attempt seems to have died. I recall that I proposed to allow tags to have a short close notation to avoid repeating the tag name. It would be like this:
The proposal was rejected. It seems that the organizers had no interest in avoiding one of the XML pain points. Given that, I am not surprised if XML 2.0 is really dead.
Nowadays, developers tend to use simpler formats like YAML and JSON to exchange data in a human-readable format. Ten years ago they would have used XML instead.
Despite the change in the mentality of the developers, once in a while we still need to deal with XML for some reason.
For instance, a few years ago I needed to develop a client and server of OpenID protocol. That is a single sign-on protocol, i.e. it allows you to login in multiple sites using the same account. It was used to let users login in the JSClasses site with the same account you use in the PHPClasses site.
OpenID itself is yet another story of a protocol design that is a pain to implement, but I will leave that story for a later article after I publish the OpenID classes that I developed.
What matters is that OpenID uses the XRDS protocol, which is meant to allow clients to discover the addresses and the features supported by the servers they need to access. XRDS is based in XML too.
Another situation for which XML may be better suited than other more simple formats, is when you need to represent certain entities that do not map to the data types used in your programming language, otherwise JSON would probably be a better choice.
For instance when you need to represent templates with special placeholders, you can use special XML tags to represent the placeholders. This is not a common situation but sometimes you may need to deal with it and XML may still be a good option.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-743332/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAX處理XML例項XML
- jQuery如何處理xml檔案程式碼例項jQueryXML
- PHP函式處理函式例項詳解PHP函式
- PHP多程式處理並行處理任務例項(轉,備用)PHP並行
- ■ 例項學習 PHP 之表單處理篇 (轉)PHP
- 演示中斷處理的例項(例項六)(轉)
- GaussDB(分散式)例項故障處理分散式
- php例項化物件的例項方法PHP物件
- xml處理的問題XML
- php讀取xml資料庫欄位超長處理PHPXML資料庫
- VUE例項:使用 CSS Filter 處理圖片VueCSSFilter
- Java經典例項:處理單個字串Java字串
- 資料處理等待效果例項程式碼
- 用PHP處理png圖片白色背景色改為透明色的例項程式碼PHP
- jQuery對xml檔案的解析例項jQueryXML
- javascript操作xml程式碼例項JavaScriptXML
- NLP自然語言處理中的hanlp分詞例項自然語言處理HanLP分詞
- 傳真文件自動化處理的應用例項
- Go xml檔案處理GoXML
- PHP影像處理繪圖、水印、驗證碼、影像壓縮技術例項總結PHP繪圖
- Nacos - 服務端處理例項列表請求服務端
- 機器學習處理流程、特徵工程,模型設計例項機器學習特徵工程模型
- APUE 7-3 終止處理程式例項
- Python驗證碼識別處理例項Python
- CSRF的防禦例項(PHP)PHP
- PHP呼叫Webservice例項PHPWeb
- XML程式設計例項(二) (轉)XML程式設計
- Java XML程式設計例項解析JavaXML程式設計
- 對pandas進行資料預處理的例項講解
- 【Mysql】mysql事務處理用法與例項詳解MySql
- jQuery處理json格式資料程式碼例項jQueryJSON
- hover事件延遲處理程式碼例項詳解事件
- 常見路由器故障處理例項詳解路由器
- 使用JAXB處理JAVA和XMLJavaXML
- 用JDOM處理XML文件 (轉)XML
- XML輕鬆學習手冊(6)XML例項解析(轉)XML
- 資料庫中的XML應用例項 (轉)資料庫XML
- jQuery解析xml檔案程式碼例項jQueryXML