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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- php例項化物件的例項方法PHP物件
- GaussDB(分散式)例項故障處理分散式
- VUE例項:使用 CSS Filter 處理圖片VueCSSFilter
- 用PHP處理png圖片白色背景色改為透明色的例項程式碼PHP
- NLP自然語言處理中的hanlp分詞例項自然語言處理HanLP分詞
- PHP影像處理繪圖、水印、驗證碼、影像壓縮技術例項總結PHP繪圖
- Nacos - 服務端處理例項列表請求服務端
- Go xml檔案處理GoXML
- 對pandas進行資料預處理的例項講解
- 製作PHP的RPM包例項PHP
- PHP漏洞挖掘思路+例項PHP
- PHP 完整表單例項PHP單例
- XML節點自動生成簡單例項XML單例
- 腦機介面例項二:腦電訊號CSP處理腦機介面
- 前端如何處理xml配置檔案?前端XML
- JSP筆記-XML 資料處理JS筆記XML
- 分享一下 Laravel 的中時間的簡單處理方式例項Laravel
- PHP弱型別引發的漏洞例項PHP型別
- ctags 處理 PHP traitPHPAI
- PHP 時間處理PHP
- PHP 錯誤處理PHP
- php錯誤處理PHP
- MySQL資料庫的事務處理用法與例項程式碼詳解MySql資料庫
- linux 透過xmllint處理xml檔案LinuxXML
- 處理XML資料應用實踐XML
- Python資料處理(一):處理 JSON、XML、CSV 三種格式資料PythonJSONXML
- java 如何簡單快速處理 xml 中的資料JavaXML
- PHP 陣列 & 字串處理PHP陣列字串
- PHP 核心 - 異常處理PHP
- php表單處理-143PHP
- php建立XMLPHPXML
- PHP7 新增功能詳解(例項)PHP
- PHP處理密碼的幾種方式PHP密碼
- php 與 nginx 的兩種處理方式PHPNginx
- 利用ASP傳送和接收XML資料的處理方法XML
- iPhone中XML處理以及網路上的圖片顯示iPhoneXML
- Nest 中處理 XML 型別的請求與響應XML型別
- mysqlconnect bug 處理一例。MySql
- 解析XML檔案時,無效的XML 字元 (Unicode: 0x7)異常處理XML字元Unicode