作者edash (团长)
看板PHP
标题[请益] XML解析
时间Mon Oct 14 08:59:29 2013
Say you have a set of XML files, each containing information about a book,
and you want to build an index showing the document title and its author for
the collection.
You need to parse the XML files to recognize the title and author elements
and their contents.
You could do this by hand with regular expressions and string functions such
as strtok(), but it’s a lot more complex than it seems.
In addition, such methods are prone to breakage even with valid XML documents.
The easiest and quickest solution is to use one of the XML parsers that
ship with PHP.
------
板友好,最近念到「XML parsing」章节,上方是其中一段,为阅读方便故适当分行。
依个人解读,前三句主要是讲解析XML,可以使用regular expression或strtok函式。
到第四句就不太懂,因为依字面解读,应该是说前述两种做法,容易毁损XML文件。
一来不确定自己解读是否正确,二来即使解读正确,也不太清楚其原因为何。
还请板友多指教,谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 111.248.73.82
1F:→ MOONRAKER:又没写进去当然不会破(breakage) 当然是说读出来会破 10/14 09:26
2F:→ PsMonkey:大抵上就跟你不会享用 RegExp 写 compiler 的道理一样 XD 10/14 11:16
3F:→ danny8376:简单来说 自己造轮子搞不好会做成方的 10/14 12:33
4F:→ danny8376:就算XML本身是正确的 但你规则可能有错 所以读到的 10/14 12:34
5F:→ danny8376:内容有可能有问题 反正有现成的工具就拿来用 10/14 12:34
6F:→ danny8376:除非你对写parser有兴趣 不然你不可能写得比内建的好 10/14 12:34
7F:→ journey892:请问各位大大,如果用XML Schema会不会比较好?用.xsd 10/14 13:44
8F:→ journey892:.xsd parse .xml 10/14 13:44
9F:→ edash:谢谢大家回应 10/14 23:47