{"id":195,"date":"2016-04-19T18:06:01","date_gmt":"2016-04-19T10:06:01","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=195"},"modified":"2016-04-20T14:54:00","modified_gmt":"2016-04-20T06:54:00","slug":"%e7%ac%ac12%e7%ab%a0-xml","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=195","title":{"rendered":"\u7b2c12\u7ae0 XML"},"content":{"rendered":"<p>\uff081\uff09XML\u662f\u4e00\u79cd\u63cf\u8ff0\u5c42\u6b21\u7ed3\u6784\u6570\u636e\u7684\u901a\u7528\u65b9\u6cd5\u3002\u4e00\u4e2aXML\u6587\u4ef6\u5305\u542b\u4e86\u4e00\u4e2a\u6216\u591a\u4e2aelement\uff0c\u5b83\u88ab\u9650\u5b9a\u5728\u4e00\u5bf9tag\u4e2d\u3002<\/p>\n<p>&lt;foo&gt; \u2460<br \/>\n&lt;\/foo&gt; \u2461<\/p>\n<ol>\n<li>\u8fd9\u662ffoo element\u7684\u5f00\u59cb\u3002<\/li>\n<li>\u8fd9\u662ffoo element\u7684\u7ed3\u5c3e\u3002\u6bcf\u4e2a\u4e00\u4e2a\u5f00\u59cbtag\u5fc5\u987b\u6709\u4e00\u4e2a\u7ed3\u675ftag\u3002<\/li>\n<\/ol>\n<p>element\u53ef\u4ee5\u5d4c\u5957\u4efb\u610f\u6df1\u5ea6\uff1a<br \/>\n<code>&lt;foo&gt;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 &lt;bar&gt;&lt;\/bar&gt;<\/code><br \/>\n<code>&lt;\/foo&gt;<\/code><\/p>\n<p>\u5728XML\u6587\u6863\u4e2d\u7b2c\u4e00\u4e2aelement\u88ab\u79f0\u4f5croot\u3002\u4e00\u4e2aXML\u6587\u6863\u4ec5\u80fd\u6709\u4e00\u4e2aroot element\u3002\u4e0b\u9762\u7684\u4f8b\u5b50<strong>\u4e0d\u662f\u4e00\u4e2aXML\u6587\u6863<\/strong>\uff0c\u56e0\u4e3a\u5b83\u6709\u4e24\u4e2a\u6839\uff1a<br \/>\n&lt;foo&gt;&lt;\/foo&gt;<br \/>\n&lt;bar&gt;&lt;\/bar&gt;<\/p>\n<p>element\u80fd\u6709\u5c5e\u6027\uff0c\u4e00\u4e2a\u201c\u540d\u5b57&#8211;\u503c\u201d\u5bf9\u3002\u5c5e\u6027\u653e\u5728\u5f00\u59cbtag\u4e2d\uff0c\u6bcf\u4e2a\u5c5e\u6027\u7528\u7a7a\u683c\u5206\u9694\u3002\u5728\u4e00\u4e2aelement\u4e2d\u5c5e\u6027\u540d\u4e0d\u80fd\u91cd\u590d\uff0c\u800c\u5c5e\u6027\u7684\u503c\u653e\u5728\u5f15\u53f7\u91cc\uff08\u53ef\u4ee5\u7528\u53cc\u5f15\u53f7\uff0c\u4e5f\u53ef\u4ee5\u7528\u5355\u5f15\u53f7\uff09\u3002<\/p>\n<p><code> &lt;foo lang='en'&gt; \u2460<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 &lt;bar id=xml-'papayawhip' lang=\"fr\"&gt;&lt;\/bar&gt; \u2461<\/code><br \/>\n<code>&lt;\/foo&gt;<\/code><\/p>\n<ol>\n<li>foo element\u6709\u4e00\u4e2a\u5c5e\u6027\uff0c\u540d\u4e3a\uff1alang\uff1b\u503c\u4e3a\uff1aen\u3002<\/li>\n<li>bar element\u6709\u4e24\u4e2a\u5c5e\u6027\uff0c\u540d\u4e3a\uff1aid\u548clang\u3002lang\u7684\u503c\u4e3afr.\u8fd9\u548cfoo\u4e2d\u7684lang\u6ca1\u6709\u51b2\u7a81\u3002\u6bcf\u4e2aelement\u90fd\u6709\u81ea\u5df1\u7684\u4e00\u7ec4\u5c5e\u6027\u3002\u591a\u4e2a\u5c5e\u6027\u4e4b\u95f4\u6ca1\u6709\u5148\u540e\u987a\u5e8f\uff0c\u4e5f\u6ca1\u6709\u9650\u5236\u5c5e\u6027\u7684\u6570\u91cf\u3002<\/li>\n<\/ol>\n<p>element\u53ef\u4ee5\u6709\u6587\u672c\u4e0a\u4e0b\u6587\uff1a<br \/>\n<code>&lt;foo lang='en'&gt;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 &lt;bar lang='fr'&gt;PapayaWhip&lt;\/bar&gt;<\/code><br \/>\n<code>&lt;\/foo&gt;<\/code><\/p>\n<p>element\u4e0d\u5305\u542b\u6587\u672c\u4e5f\u6ca1\u6709\u5d4c\u5957\uff0c\u90a3\u4e48\u5b83\u662f\u7a7a\u7684\uff1a<br \/>\n&lt;foo&gt;&lt;\/foo&gt;<\/p>\n<p>\u5728element\u7684\u5f00\u59cbtag\u4e2d\u653e\u4e00\u4e2a\u659c\u7ebf\u53ef\u4ee5\u6ca1\u6709\u7ed3\u5c3etag\uff0c\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u5199\u6210\uff1a<br \/>\n&lt;foo \/&gt;<\/p>\n<p>\u50cfpython\u53ef\u4ee5\u5b9a\u4e49\u4e0d\u540c\u7684<em>\u6a21\u5757<\/em>\u4e00\u6837\uff0c<strong>XML\u4e5f\u80fd\u5b9a\u4e49\u4e0d\u540c\u7684\u540d\u5b57\u7a7a\u95f4<\/strong>\u3002\u540d\u5b57\u7a7a\u95f4\u770b\u8d77\u6765\u50cf\u662f\u4e00\u4e2aURL\u3002\u4f7f\u7528<strong>xmlns<\/strong>\u5b9a\u4e49\u9ed8\u8ba4\u540d\u5b57\u7a7a\u95f4\uff0c\u540d\u5b57\u7a7a\u95f4\u50cf\u662f\u4e00\u4e2a\u5c5e\u6027\uff0c\u4f46\u662f\u6709\u4e0d\u540c\u7684\u76ee\u5730\u3002<\/p>\n<p><code> &lt;feed xmlns='http:\/\/www.w3.org\/2005\/Atom'&gt;\u00a0 \u2460<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 &lt;title&gt;dive into mark&lt;\/title&gt;\u00a0\u00a0\u00a0\u00a0 \u2461<\/code><br \/>\n<code>&lt;\/feed&gt;<\/code><\/p>\n<ol>\n<li>feed element\u662f\u5728http:\/\/www.w3.org\/2005\/Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002<\/li>\n<li>title element\u540c\u6837\u662f\u5728http:\/\/www.w3.org\/2005\/Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002\u540d\u5b57\u7a7a\u95f4\u58f0\u660e\u5f71\u54cdelement\u53ca\u5176\u5b50\u5143\u7d20\u5728\u54ea\u91cc\u58f0\u540d\u3002<\/li>\n<\/ol>\n<p><strong>\u53ef\u4ee5\u4f7f\u7528xmlns:prefix\u5b9a\u4e49\u540d\u5b57\u7a7a\u95f4\u548c\u524d\u7f00\u3002\u7136\u540e\u5728\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684\u6bcf\u4e2aelement\u58f0\u540d\u65f6\u5fc5\u9700\u663e\u793a\u5e26\u4e0a\u524d\u7f00\u3002<\/strong><\/p>\n<p><code> &lt;atom:feed xmlns:atom='http:\/\/www.w3.org\/2005\/Atom'&gt; \u2460<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0 &lt;atom:title&gt;dive into mark&lt;\/atom:title&gt; \u2461<\/code><br \/>\n<code>&lt;\/atom:feed&gt;<\/code><\/p>\n<ol>\n<li>feed element\u5728http:\/\/www.w3.org\/2005\/Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002<\/li>\n<li>title element\u4e5f\u5728http:\/\/www.w3.org\/2005\/Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002<\/li>\n<\/ol>\n<p>XML\u5206\u6790\u5668\u62c5\u5fc3\u4e4b\u524d\u6709\u4e24\u4e2aXML\u6587\u6863\u6709\u76f8\u540c\u7684\u6807\u793a\uff08\u540d\u5b57\u7a7a\u95f4 + element\u540d = XML\u6807\u793a\uff09\u3002\u524d\u7f00\u7684\u5b58\u5728\u53ea\u662f\u4e3a\u4e86\u6307\u5411\u540d\u5b57\u7a7a\u95f4\uff0c\u800c\u5b9e\u9645\u4e0a\u524d\u7f00\uff08atom:\uff09\u662f\u65e0\u5173\u7d27\u8981\u7684\u3002<strong>\u540d\u5b57\u7a7a\u95f4\u3001element\u540d\u3001\u5c5e\u6027\u540d\u548c\u6bcf\u4e2aelement\u7684\u6587\u672c\u4e0a\u4e0b\u6587\u90fd\u76f8\u540c\uff0c\u90a3\u4e48\u4e24\u4e2aXML\u6587\u6863\u662f\u76f8\u540c\u7684\u3002<\/strong><\/p>\n<p>\u6700\u540e\uff0c<strong>XML\u6587\u6863\u53ef\u4ee5\u5728\u7b2c\u4e00\u884c\u5305\u542b\u5b57\u7b26\u7f16\u7801\u4fe1\u606f<\/strong>\uff08\u5728root element\u4e4b\u524d\uff09<br \/>\n&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;<\/p>\n<p>\uff082\uff09atom feed\u7684\u7ed3\u6784<\/p>\n<p>\u8ba9\u6211\u4eec\u60f3\u4e00\u4e0b\u535a\u5ba2\u6216\u4efb\u4f55\u7ecf\u5e38\u66f4\u65b0\u7684\u5185\u5bb9\u3002\u7ad9\u70b9\u81ea\u5df1\u6709\u6807\u9898\u3001\u5b50\u6807\u9898\u3001\u6700\u540e\u66f4\u65b0\u65e5\u671f\u3001\u4e0d\u540c\u65f6\u95f4\u7684\u6587\u7ae0\u5217\u8868\u3002\u6bcf\u4e2a\u6587\u7ae0\u540c\u6837\u6709\u6807\u9898\u3001\u7b2c\u4e00\u6b21\u53d1\u5e03\u65f6\u95f4\uff08\u53ef\u80fd\u8fd8\u6709\u6700\u540e\u66f4\u65b0\u65e5\u671f\uff09\u548c\u552f\u4e00\u7684URL\u3002<\/p>\n<p>Atom syndication\u683c\u5f0f\u88ab\u8bbe\u8ba1\u51fa\u6765\uff0c\u7528\u6807\u51c6\u683c\u5f0f\u6355\u83b7\u6240\u6709\u7684\u8fd9\u4e9b\u4fe1\u606f\u3002\u867d\u7136\u4e0d\u540c\u7684\u7ad9\u70b9\u7684\u8bbe\u8ba1\u3001\u533a\u57df\u548c\u89c6\u9891\uff0c\u4f46\u662f\u5b83\u4eec\u90fd\u6709\u4e00\u4e9b\u76f8\u540c\u7684\u57fa\u672c\u4fe1\u606f\u3002\u5982\uff1a\u6807\u9898\u548c\u4f5c\u8005<\/p>\n<p><strong>\u5728root element\u4e2d\uff0c\u6bcf\u4e2aatom feed \u5728\u540d\u5b57\u7a7a\u95f4\u4e2d\u5171\u4eab\uff1a<\/strong><\/p>\n<p><code> &lt;feed xmlns='http:\/\/www.w3.org\/2005\/Atom' \u2460<\/code><br \/>\n<code>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 xml:lang='en'&gt; \u2461<\/code><\/p>\n<ol>\n<li>http:\/\/www.w3.org\/2005\/Atom\u662fatom\u540d\u5b57\u7a7a\u95f4\u3002<\/li>\n<li>\u4efb\u4f55element\u80fd\u5305\u542bxml:lang\u5c5e\u6027\uff0c\u5b83\u58f0\u660e\u4e86element\u53ca\u5176\u5b50\u5143\u7d20\u7684\u8bed\u8a00\uff0c\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2dxml:lang\u5c5e\u6027\u5728root element\u58f0\u660e\u4e86\u4e00\u6b21\uff0c\u8fd9\u610f\u5473\u7740\u5168\u90e8\u7684feed\u90fd\u662f\u82f1\u8bed\u3002<\/li>\n<\/ol>\n<p>atom feed\u5173\u4e8e\u5b83\u81ea\u5df1\u5305\u542b\u4e86\u51e0\u90e8\u5206\u4fe1\u606f\u3002\u8fd9\u91cc\u58f0\u660e\u4e86\u51e0\u4e2aroot\u7ea7feed\u5143\u7d20\u7684\u5b50\u5143\u7d20\u3002<\/p>\n<p><code> &lt;feed xmlns='http:\/\/www.w3.org\/2005\/Atom' xml:lang='en'&gt;<\/code><br \/>\n<code>\u00a0 &lt;title&gt;dive into mark&lt;\/title&gt; \u2460<\/code><br \/>\n<code>\u00a0 &lt;subtitle&gt;currently between addictions&lt;\/subtitle&gt; \u2461<\/code><br \/>\n<code>\u00a0 &lt;id&gt;tag:diveintomark.org,2001-07-29:\/&lt;\/id&gt; \u2462<\/code><br \/>\n<code>\u00a0 &lt;updated&gt;2009-03-27T21:56:07Z&lt;\/updated&gt; \u2463<\/code><br \/>\n<code>\u00a0 &lt;link rel='alternate' type='text\/html' href='http:\/\/diveintomark.org\/'\/&gt; \u2464<\/code><\/p>\n<ol>\n<li>\u8fd9\u4e2afeed\u7684\u6807\u9898\u662f\uff1adive into mark<\/li>\n<li>\u8fd9\u4e2afeed\u7684\u5b50\u6807\u9898\u662f\uff1acurrently between addictions.<\/li>\n<li>\u6bcf\u4e2afeed\u9700\u8981\u4e00\u4e2a\u5168\u5c40\u552f\u4e00\u6807\u793a\u7b26\u3002\uff08\u521b\u5efa\u65b9\u6cd5\u8be6\u89c1\uff1ahttp:\/\/www.ietf.org\/rfc\/rfc4151.txt\uff09<\/li>\n<li>\u8fd9\u4e2afeed\u6700\u540e\u66f4\u65b0\u65e5\u671f\u662f\uff1a2009\u5e743\u670827\u65e521\u70b956\u520607\u79d2\u3002<\/li>\n<li>\u73b0\u5728\u662f\u6700\u8da3\u7684\u90e8\u5206\u3002link\u5143\u7d20\u6ca1\u6709\u6587\u672c\u4e0a\u4e0b\u6587\uff0c\u4f46\u662f\u5b83\u6709\u4e09\u4e2a\u5c5e\u6027\uff1arel\uff0ctype\u548chref\u3002rel\u503c\u544a\u8bc9\u6211\u4eec\u8fd9\u662f\u4ec0\u4e48\u7c7b\u578b\u7684\u503c\uff0crel=&#8217;alternate&#8217;\u610f\u5473\u7740\u8fd9\u662f\u4e00\u4e2a\u94fe\u63a5\uff0c\u94fe\u63a5\u5230\u5f53\u524dfeed\u63cf\u8ff0\u7684\u53e6\u4e00\u4e2a\u5730\u5740\uff08 means that this is a link<br \/>\nto an alternate representation of this feed.<br \/>\n\uff09\u3002type=&#8217;text\/html&#8217;\u5c5e\u6027\u610f\u5473\u7740\uff0c\u8fd9\u4e2a\u94fe\u63a5\u662f\u4e00\u4e2ahtml\u9875\u9762\u3002\u94fe\u63a5\u76ee\u6807\u7684\u5740\u5740\u5728href\u5c5e\u6027\u4e2d\u3002<\/li>\n<li>\u6574\u4f53\u4e0b\u6765\u7684\u610f\u601d\u5c31\u662f\uff1a\u8fd9\u662f\u4e00\u4e2a\u7ad9\u70b9\u540d\u4e3a\u201cdive into mark\u201d\u7684feed\uff0c\u5b83\u7684\u53ef\u7528\u5730\u5740\u662fhttp:\/\/diveintomark.org\/ \u5e76\u4e14\u6700\u540e\u7684\u66f4\u65b0\u65f6\u95f4\u4e3a2009\u5e743\u670827\u65e5\u3002<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\uff1a\u867d\u7136\u5143\u7d20\u7684\u987a\u5e8f\u548cXML\u6587\u6863\u6709\u5173\uff0c\u4f46atom feed\u548c\u987a\u5e8f\u65e0\u5173\u3002<\/strong><\/p>\n<p>\u5728feed\u7ea7meta\u6570\u636e\u540e\u662f\u6700\u8fd1\u6587\u7ae0\u5217\u8868\u3002\u6587\u7ae0\u5217\u8868\u770b\u8d77\u6765\u662f\u8fd9\u6837\u7684\uff1a<br \/>\n<code>&lt;entry&gt;<\/code><br \/>\n<code>\u00a0&lt;author&gt; \u2460<\/code><br \/>\n<code>\u00a0\u00a0 &lt;name&gt;Mark&lt;\/name&gt;<\/code><br \/>\n<code>\u00a0\u00a0 &lt;uri&gt;http:\/\/diveintomark.org\/&lt;\/uri&gt;<\/code><br \/>\n<code>\u00a0&lt;\/author&gt;<\/code><br \/>\n<code>\u00a0&lt;title&gt;Dive into history, 2009 edition&lt;\/title&gt; \u2461<\/code><br \/>\n<code>\u00a0&lt;link rel='alternate' type='text\/html' \u2462<\/code><br \/>\n<code>\u00a0\u00a0 href='http:\/\/diveintomark.org\/archives\/2009\/03\/27\/dive-into-history-2009-edition'\/&gt;<\/code><br \/>\n<code>\u00a0&lt;id&gt;tag:diveintomark.org,2009-03-27:\/archives\/20090327172042&lt;\/id&gt; \u2463<\/code><br \/>\n<code>\u00a0&lt;updated&gt;2009-03-27T21:56:07Z&lt;\/updated&gt; \u2464<\/code><br \/>\n<code>\u00a0&lt;published&gt;2009-03-27T17:20:42Z&lt;\/published&gt;<\/code><br \/>\n<code>\u00a0&lt;category scheme='http:\/\/diveintomark.org' term='diveintopython'\/&gt; \u2465<\/code><br \/>\n<code>\u00a0&lt;category scheme='http:\/\/diveintomark.org' term='docbook'\/&gt;<\/code><br \/>\n<code>\u00a0&lt;category scheme='http:\/\/diveintomark.org' term='html'\/&gt;<\/code><br \/>\n<code>\u00a0&lt;summary type='html'&gt;Putting an entire chapter on one page sounds \u2466<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 bloated, but consider this &amp;mdash; my longest chapter so far<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 would be 75 printed pages, and it loads in under 5 seconds&amp;hellip;<\/code><br \/>\n<code>\u00a0\u00a0\u00a0 On dialup.&lt;\/summary&gt;<\/code><br \/>\n<code>&lt;\/entry&gt;\u00a0 \u2467<br \/>\n<\/code><\/p>\n<ol>\n<li>author\u5143\u7d20\u544a\u77e5\u8c01\u662f\u6587\u7ae0\u7684\u4f5c\u8005\u3002<\/li>\n<li>title\u5143\u7d20\u544a\u77e5\u6587\u7ae0\u6807\u9898\u3002<\/li>\n<li>\u505a\u4e3afeed\u7ea7\u94fe\u63a5\uff0c\u8fd9\u4e2alink\u5143\u7d20\u7ed9\u51fa\u4e86HTML\u7684\u5730\u5740\uff0c\u6587\u7ae0\u7684\u7248\u672c\u3002<\/li>\n<li>entry\u548cfeed\u4e00\u6837\uff0c\u9700\u8981\u552f\u4e00\u6807\u793a\u7b26\u3002<\/li>\n<li>entry\u6709\u4e24\u4e2a\u65e5\u671f\uff1a\u4e00\u4e2a\u662f\u53d1\u5e03\u65e5\u671f\u522b\u4e00\u4e2a\u6700\u540e\u4fee\u6539\u65e5\u671f\u3002<\/li>\n<li>entry\u6709\u4efb\u610f\u6570\u91cf\u7684\u5206\u7c7b\u3002\u8fd9\u7bc7\u6587\u7ae0\u5728diveintopython, docbook\u548chtml\u5206\u7c7b\u4e0b\u3002<\/li>\n<li>summary\u5143\u7d20\u7ed9\u51fa\u4e86\u4e00\u4e2a\u6587\u7ae0\u6982\u8981\uff08\u5982\u679c\u8981\u5728feed\u4e2d\u663e\u793a\u5b8c\u6574\u7684\u6587\u7ae0\u5185\u5bb9\uff0c\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u662fcontent\u5143\u7d20\uff09\u3002summary\u5143\u7d20\u6709\u4e00\u4e2atype=&#8217;html&#8217;\u7684\u5c5e\u6027\uff0c\u5b83\u8868\u793a\u8fd9\u662f\u4e00\u4e2aHTML\u7247\u6bb5\uff0c\u800c\u4e0d\u662f\u660e\u6587\u5b57\u7b26\u3002\u8fd9\u5f88\u91cd\u8981\uff0c\u56e0\u4e3a\u53ef\u4ee5\u5728\u5176\u4e2d\u63d2\u5165HTML\u7279\u5b9a\u5143\u7d20\uff08&amp;mdash\u548c&amp;hellip;\u8fd9\u4e24\u4e2a\u4f1a\u88ab\u7ffb\u8bd1\u6210\u201c\u2014\u2014\u201d\u548c\u201c\u2026\u2026\u201d\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u663e\u793a\u5b83\u4eec\uff09<\/li>\n<li>\u6700\u540e\uff0c\u662f\u7ed3\u675fentry\u5143\u7d20\u7684tag\uff0c\u4ee3\u8868\u8fd9\u7bc7\u6587\u7ae0\u7684meta\u6570\u636e\u7684\u7ed3\u5c3e\u3002<\/li>\n<\/ol>\n<h2>\uff082\uff09\u5206\u6790XML<\/h2>\n<p>python\u53ef\u4ee5\u901a\u8fc7\u51e0\u79cd\u65b9\u6cd5\u5206\u6790XML\u6587\u6863\u3002\u6709\u4f20\u7edf\u7684DOM\u548cSAX\u5206\u6790\u5668\uff0c\u4e0d\u8fc7\u73b0\u5728\u8981\u4ecb\u7ecd\u7684\u662f\u53e6\u4e00\u79cd\u5e93<strong>ElementTree<\/strong>.<\/p>\n<p><code> &gt;&gt;&gt; import xml.etree.ElementTree as etree \u2460<\/code><br \/>\n<code>&gt;&gt;&gt; tree = etree.parse('examples\/feed.xml') \u2461<\/code><br \/>\n<code>&gt;&gt;&gt; root = tree.getroot() \u2462<\/code><br \/>\n<code>&gt;&gt;&gt; root \u2463<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}feed at cd1eb0&gt;<\/code><\/p>\n<ol>\n<li>ElementTree\u662fpython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u5728xml.etree.ElementTree\u91cc\u3002<\/li>\n<li>\u8be5\u5e93\u7684\u91cd\u70b9\u662fparse()\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u6839\u636e\u6587\u4ef6\u540d\u6216\u7c7b\u4f3c\u6587\u4ef6\u7684\u5bf9\u8c61\u8fdb\u884c\u5206\u6790\u3002\u5b83\u53ea\u5bf9\u6587\u6863\u8fdb\u884c\u4e00\u6b21\u5206\u6790\uff0c\u5982\u679c\u5185\u5b58\u5f88\u5c11\u7684\u8bdd\uff0c\u5b83\u53ef\u4ee5\u9010\u6b65\u9012\u589e\u8bfb\u53d6XML\u6587\u6863\u3002<\/li>\n<li>parse()\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u63cf\u8ff0\u4e86\u6240\u6709\u7684\u6587\u6863\u3002\u8fd9\u5e76\u4e0d\u662froot element\u3002\u5f97\u5230root element\u662f\u8c03\u7528getroot()\u65b9\u6cd5\u3002<\/li>\n<li>\u5c31\u50cf\u9884\u8ba1\u7684\u90a3\u6837\uff0croot element\u662fhttp:\/\/www.w3.org\/2005\/Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684feed\u5143\u7d20\u3002\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u63cf\u8ff0\u52a0\u5f3a\u4e86\u4e00\u4e2a\u91cd\u8981\u89c2\u70b9\uff1a<strong>xml\u5143\u7d20\u7ed3\u5408\u4e86\u5b83\u7684\u540d\u5b57\u7a7a\u95f4\u548c\u5b83\u7684tag\u540d\u5b57\uff08\u6709\u65f6\u4e5f\u53eb\u672c\u5730\u540d\uff09<\/strong>\u3002\u8fd9\u4e2a\u6587\u6863\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u90fd\u5728Atom\u540d\u5b57\u7a7a\u95f4\u91cc\uff0c\u6240\u4ee5root element\u88ab\u63cf\u8ff0\u6210 {http:\/\/www.w3.org\/2005\/Atom}feed\u3002<\/li>\n<\/ol>\n<p><strong>\u6ce8\uff1aElementTree\u63cf\u8ff0XML\u5143\u7d20\u7684\u683c\u5f0f\u662f{namespace}localname\u3002\u8fd9\u79cd\u683c\u5f0f\u5c06\u4f1a\u5728ElementTree API\u4e2d\u7ecf\u5e38\u770b\u5230\u3002<\/strong><\/p>\n<h2>\uff083\uff09\u5143\u7d20\u662f\u5217\u8868<\/h2>\n<p>\u5728ElementTree APT\u4e2d\u5143\u7d20\u884c\u4e3a\u5c31\u50cf\u662f\u5217\u8868\u4e00\u6837\u3002\u5217\u8868\u4e2d\u7684\u6bcf\u4e00\u9879\u90fd\u662f\u5143\u7d20\u7684\u5b50\u5143\u7d20\u3002<\/p>\n<p><code> # \u63a5\u4e0a\u9762\u7684\u4f8b\u5b50<\/code><br \/>\n<code>&gt;&gt;&gt; root.tag \u2460<\/code><br \/>\n<code>'{http:\/\/www.w3.org\/2005\/Atom}feed'<\/code><br \/>\n<code>&gt;&gt;&gt; len(root) \u2461<\/code><br \/>\n<code>8<\/code><br \/>\n<code>&gt;&gt;&gt; for child in root: \u2462<\/code><br \/>\n<code>...\u00a0 \u00a0 print(child) \u2463<\/code><br \/>\n<code>...<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}title at e2b5d0&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}subtitle at e2b4e0&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}id at e2b6c0&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}updated at e2b6f0&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e2b4b0&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b720&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b510&gt;<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b750&gt;<\/code><\/p>\n<ol>\n<li>\u63a5\u521a\u624d\u7684\u5217\u5b50\uff0croot\u5143\u7d20\u662f{http:\/\/www.w3.org\/2005\/Atom}feed\u3002<\/li>\n<li>root\u5143\u7d20\u7684\u957f\u5ea6\u4ee3\u8868\u5b83\u7684\u5b50\u5143\u7d20\u7684\u6570\u91cf\u3002<\/li>\n<li>\u5143\u7d20\u672c\u8eab\u4e5f\u662f\u8fed\u4ee3\u5668\uff0c\u53ef\u4ee5\u8fed\u4ee3\u5b83\u7684\u6bcf\u4e00\u4e2a\u5b50\u5143\u7d20\u3002<\/li>\n<li>\u5c31\u50cf\u4f60\u770b\u5230\u7684\u90a3\u6837\u8f93\u51fa\u4e868\u4e2a\u5143\u7d20\uff0c\u524d\u4e94\u4e2a\u662ffeed\u7ea7meta\u6570\u636e\uff0c\u4e4b\u540e\u8ddf\u4e86\u4e09\u4e2aentry\u5143\u7d20\u3002<\/li>\n<\/ol>\n<p>\u8fd9\u91cc\u6709\u4e00\u70b9\u8981\u6ce8\u610ffeed\u7ea7\u522b\u7684\u5217\u8868\u53ea\u5305\u542b\u76f4\u63a5\u5b50\u5143\u7d20\uff0c\u4e0d\u80fd\u5305\u542b\u95f4\u63a5\u5b50\u5143\u7d20\uff0c\u5982entry\u7684\u5b50\u5143\u7d20\u662f\u65e0\u6cd5\u5305\u542b\u5728feed\u7ea7\u5217\u8868\u4e2d\u7684\uff0centry\u7684\u5b50\u5143\u7d20\u53ea\u80fd\u5728entry\u81ea\u5df1\u7684\u5217\u8868\u4e2d\u3002\u4ee5\u540e\u4f1a\u4ecb\u7ecd\u4e8c\u79cd\u65b9\u6cd5\uff0c\u8fd9\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u6df1\u5ea6\u7684\u5143\u7d20\u3002<\/p>\n<h2>\uff084\uff09\u5c5e\u6027\u662f\u5b57\u5178<\/h2>\n<p>XML\u5e76\u4e0d\u4ec5\u4ec5\u662f\u6c47\u96c6\u5143\u7d20\uff1b\u6bcf\u4e2a\u5143\u7d20\u4e5f\u80fd\u6709\u5b83\u81ea\u5df1\u7684\u5c5e\u6027\u96c6\u3002\u4e00\u4f46\u6307\u5411\u4e86\u67d0\u4e2a\u7279\u5b9a\u7684\u5143\u7d20\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u83b7\u5f97\u5b83\u7684\u5c5e\u6027\u5e76\u505a\u4e3apython\u7684\u5b57\u5178\uff08dictionary\uff09\u3002<\/p>\n<p><code> # continuing from the previous example<\/code><br \/>\n<code>&gt;&gt;&gt; root.attrib \u2460<\/code><br \/>\n<code>{'{http:\/\/www.w3.org\/XML\/1998\/namespace}lang': 'en'}<\/code><br \/>\n<code>&gt;&gt;&gt; root[4] \u2461<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e181b0&gt;<\/code><br \/>\n<code>&gt;&gt;&gt; root[4].attrib \u2462<\/code><br \/>\n<code>{'href': 'http:\/\/diveintomark.org\/',<\/code><br \/>\n<code>'type': 'text\/html',<\/code><br \/>\n<code>'rel': 'alternate'}<\/code><br \/>\n<code>&gt;&gt;&gt; root[3] \u2463<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}updated at e2b4e0&gt;<\/code><br \/>\n<code>&gt;&gt;&gt; root[3].attrib \u2464<\/code><br \/>\n<code>{}<\/code><\/p>\n<ol>\n<li>attrib\u662f\u5143\u7d20\u5c5e\u6027\u7684\u5b57\u5178<\/li>\n<li>\u7b2c5\u4e2a\u5b50\u5143\u7d20\u662f<code>link<\/code>\u5143\u7d20<\/li>\n<li>link\u5143\u7d20\u6709\u4e09\u4e2a\u5c5e\u6027\uff1ahref, type, \u548crel\u3002<\/li>\n<li>\u7b2c4\u4e2a\u5b50\u5143\u7d20\u662fupdated\u5143\u7d20\u3002<\/li>\n<li>\u56e0\u4e3aupdated\u5143\u7d20\u6ca1\u6709\u5c5e\u6027\uff0c\u6240\u4ee5\u5b83\u7684attrib\u662f\u7a7a\u5b57\u5178\u3002<\/li>\n<\/ol>\n<h2>\uff085\uff09\u5728XML\u6587\u6863\u4e2d\u641c\u7d22\u8282\u70b9<\/h2>\n<p><code> &gt;&gt;&gt; import xml.etree.ElementTree as etree<\/code><br \/>\n<code>&gt;&gt;&gt; tree = etree.parse('examples\/feed.xml')<\/code><br \/>\n<code>&gt;&gt;&gt; root = tree.getroot()<\/code><br \/>\n<code>&gt;&gt;&gt; root.findall('{http:\/\/www.w3.org\/2005\/Atom}entry') \u2460<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b4e0&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b510&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b540&gt;]<\/code><br \/>\n<code>&gt;&gt;&gt; root.tag<\/code><br \/>\n<code>'{http:\/\/www.w3.org\/2005\/Atom}feed'<\/code><br \/>\n<code>&gt;&gt;&gt; root.findall('{http:\/\/www.w3.org\/2005\/Atom}feed') \u2461<\/code><br \/>\n<code>[]<\/code><br \/>\n<code>&gt;&gt;&gt; root.findall('{http:\/\/www.w3.org\/2005\/Atom}author') \u2462<\/code><br \/>\n<code>[]<\/code><\/p>\n<ol>\n<li>findall()\u65b9\u6cd5\u627e\u5230\u6240\u6709\u5339\u914d\u7684\u5b50\u5143\u7d20\u3002<\/li>\n<li>\u6240\u6709\u7684\u5143\u7d20\u90fd\u5728root\u5143\u7d20\u4e4b\u4e0b\uff0c\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u81ea\u5df1\u7684findall()\u65b9\u6cd5\u3002\u5339\u914d\u5728\u5176\u4e0b\u65b9\u6240\u6709\u5b50\u5143\u7d20\u3002\u6ca1\u6709\u8fd4\u56de\u503c\u662f\u56e0\u4e3a\u5728root\u4e0b\u9762\u6ca1\u6709\u540d\u4e3afeed\u7684\u5143\u7d20\u3002<\/li>\n<li>\u6ca1\u6709\u8fd4\u56de\u503c\u7684\u539f\u56e0\u662fauthor\u4e0d\u662froot\u7684\u76f4\u63a5\u5b50\u5143\u7d20\u3002<\/li>\n<\/ol>\n<p>\u8fd8\u6709\u4e00\u4e2a<code>find()<\/code>\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u5143\u7d20\u3002<\/p>\n<p><code> &gt;&gt;&gt; entries = tree.findall('{http:\/\/www.w3.org\/2005\/Atom}entry') \u2460<\/code><br \/>\n<code>&gt;&gt;&gt; len(entries)<\/code><br \/>\n<code>3<\/code><br \/>\n<code>&gt;&gt;&gt; title_element = entries[0].find('{http:\/\/www.w3.org\/2005\/Atom}title') \u2461<\/code><br \/>\n<code>&gt;&gt;&gt; title_element.text<\/code><br \/>\n<code>'Dive into history, 2009 edition'<\/code><br \/>\n<code>&gt;&gt;&gt; foo_element = entries[0].find('{http:\/\/www.w3.org\/2005\/Atom}foo') \u2462<\/code><br \/>\n<code>&gt;&gt;&gt; foo_element<\/code><br \/>\n<code>&gt;&gt;&gt; type(foo_element)<\/code><br \/>\n<code>&lt;class 'NoneType'&gt;<\/code><\/p>\n<ol>\n<li>\u627e\u5230\u6240\u6709atom:entry\u5143\u7d20\u3002<\/li>\n<li>find()\u65b9\u6cd5\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5339\u914d\u7684\u5143\u7d20\u3002<\/li>\n<li>\u6ca1\u6709\u627e\u5230\u4efb\u4f55\u5143\u7d20\u6240\u4ee5\u53cd\u56deNone\u3002<\/li>\n<li>\u5728\u5e03\u5c14\u4e0a\u4e0b\u6587\u4e2d\u5224\u65adfind()\u662f\u5426\u8fd4\u56de\u4e86\u503c\uff0c\u8bf7\u4f7f\u7528\uff1a<br \/>\n<code> if element.find('...') is not None<\/code><\/li>\n<\/ol>\n<h2>\uff086\uff09\u641c\u7d22\u4efb\u610f\u6df1\u5ea6<\/h2>\n<p><code> &gt;&gt;&gt; all_links = tree.findall('\/\/{http:\/\/www.w3.org\/2005\/Atom}link') \u2460<\/code><br \/>\n<code>&gt;&gt;&gt; all_links<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e181b0&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e2b570&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e2b480&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at e2b5a0&gt;]<\/code><br \/>\n<code>&gt;&gt;&gt; all_links[0].attrib \u2461<\/code><br \/>\n<code>{'href': 'http:\/\/diveintomark.org\/',<\/code><br \/>\n<code>'type': 'text\/html',<\/code><br \/>\n<code>'rel': 'alternate'}<\/code><br \/>\n<code>&gt;&gt;&gt; all_links[1].attrib \u2462<\/code><br \/>\n<code>{'href': 'http:\/\/diveintomark.org\/archives\/2009\/03\/27\/dive-into-history-2009-edition',<\/code><br \/>\n<code>'type': 'text\/html',<\/code><br \/>\n<code>'rel': 'alternate'}<\/code><br \/>\n<code>&gt;&gt;&gt; all_links[2].attrib<\/code><br \/>\n<code>{'href': 'http:\/\/diveintomark.org\/archives\/2009\/03\/21\/accessibility-is-a-harsh-mistress',<\/code><br \/>\n<code>'type': 'text\/html',<\/code><br \/>\n<code>'rel': 'alternate'}<\/code><br \/>\n<code>&gt;&gt;&gt; all_links[3].attrib<\/code><br \/>\n<code>{'href': 'http:\/\/diveintomark.org\/archives\/2008\/12\/18\/give-part-1-container-formats',<\/code><br \/>\n<code>'type': 'text\/html',<\/code><br \/>\n<code>'rel': 'alternate'}<\/code><\/p>\n<ol>\n<li>\u8fd9\u4e2a\u67e5\u8be2\u548c\u4e4b\u524d\u7684\u67e5\u8be2\u6ca1\u6709\u4ec0\u4e48\u4e0d\u540c\uff0c\u53ea\u662f\u591a\u4e86\u4e24\u4e2a\u659c\u7ebf\u3002\u8fd9\u4e24\u4e2a\u659c\u7ebf\u7684\u610f\u601d\u662f\u201c\u641c\u7d22\u4efb\u610f\u6df1\u5ea6\u201d\u3002\u6240\u4ee5\u8fd9\u91cc\u5217\u51fa\u4e864\u6761link\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a\u3002<\/li>\n<li>\u7b2c\u4e00\u4e2a\u7ed3\u679c\u662froot\u5143\u7d20\u7684\u76f4\u63a5\u5b50\u5143\u7d20\u3002\u53ef\u4ee5\u4ece\u5b83\u7684\u5c5e\u6027\u4e2d\u770b\u51fa\u8fd9\u662f\u4e00\u4e2afeed\u7ea7\u94fe\u63a5\u5230\u4e00\u4e2aHTML\u9875\u9762\u3002<\/li>\n<li>\u5176\u4ed6\u4e09\u4e2a\u662fentry\u7ea7\u94fe\u63a5\u3002<\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0cElementTree\u7684findall()\u65b9\u6cd5\u6709\u5f88\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u4f46\u662f\u67e5\u8be2\u8bed\u8a00\u53ef\u80fd\u4f1a\u8ba9\u4f60\u611f\u5230\u60ca\u8bb6\u3002\u5b83\u7684\u7ba1\u65b9\u63cf\u8ff0\u4e3a\u201climited support for XPath expressions.\u201dXPath\u662f\u67e5\u8be2XML\u6587\u6863\u7684W3C\u6807\u51c6\u3002ElementTree\u7684\u67e5\u8be2\u8bed\u8a00\u548cXPath\u7684\u57fa\u672c\u67e5\u8be2\u5f88\u76f8\u4f3c\uff0c\u4f46\u662f\u5982\u679c\u4f60\u5df2\u7ecf\u4e86\u89e3\u4e86XPath\u7684\u8bdd\uff0c\u4e0d\u540c\u7684\u5730\u65b9\u4f1a\u8ba9\u4f60\u611f\u89c9\u5f88\u70e6\u4eba\u3002\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u4e00\u4e0bElementTree api\u7684\u7b2c\u4e09\u65b9XML\u5e93\u6269\u5c55\uff0c\u652f\u6301\u5b8c\u6574\u7684XPath\u3002<\/p>\n<h2>\uff087\uff09LXML<\/h2>\n<p>lxml\u662f\u4e00\u4e2a\u5efa\u7acb\u5728libxml2\u5206\u6790\u5668\u4e4b\u4e0a\u7684\u5f00\u6e90\u7b2c\u4e09\u65b9\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86100%\u517c\u5bb9ElementTree API\uff0c\u5e76\u652f\u6301\u6269\u5c55\u4e86\u5b8c\u6574\u7684XPath 1.0\u6807\u51c6\u548c\u5c11\u91cf\u5176\u5b83\u529f\u80fd\u3002\u8be5\u5e93\u9700\u8981\u5355\u72ec\u5b89\u88c5\u3002<\/p>\n<p><code> &gt;&gt;&gt; from lxml import etree \u2460<\/code><br \/>\n<code>&gt;&gt;&gt; tree = etree.parse('examples\/feed.xml') \u2461<\/code><br \/>\n<code>&gt;&gt;&gt; root = tree.getroot() \u2462<\/code><br \/>\n<code>&gt;&gt;&gt; root.findall('{http:\/\/www.w3.org\/2005\/Atom}entry') \u2463<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b4e0&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b510&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}entry at e2b540&gt;]<\/code><br \/>\n1. Once imported, lxml provides the same API as the built-in ElementTree library.<br \/>\n2. parse() function: same as ElementTree.<br \/>\n3. getroot() method: also the same.<br \/>\n4. findall() method: exactly the same.<\/p>\n<p><strong>lxml\u4e0d\u4ec5\u4ec5\u6bd4ElementTree\u5feb\uff0c\u5b83\u7684findall()\u65b9\u6cd5\u652f\u6301\u66f4\u590d\u6742\u7684\u8868\u8fbe\u5f0f\u3002<\/strong><\/p>\n<p><code> &gt;&gt;&gt; import lxml.etree \u2460<\/code><br \/>\n<code>&gt;&gt;&gt; tree = lxml.etree.parse('examples\/feed.xml')<\/code><br \/>\n<code>&gt;&gt;&gt; tree.findall('\/\/{http:\/\/www.w3.org\/2005\/Atom}*[@href]') \u2461<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at eeb8a0&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at eeb990&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at eeb960&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at eeb9c0&gt;]<\/code><br \/>\n<code>&gt;&gt;&gt; tree.findall(\"\/\/{http:\/\/www.w3.org\/2005\/Atom}*[@href='http:\/\/diveintomark.org\/']\") \u2462<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}link at eeb930&gt;]<\/code><br \/>\n<code>&gt;&gt;&gt; NS = '{http:\/\/www.w3.org\/2005\/Atom}'<\/code><br \/>\n<code>&gt;&gt;&gt; tree.findall('\/\/{NS}author[{NS}uri]'.format(NS=NS)) \u2463<\/code><br \/>\n<code>[&lt;Element {http:\/\/www.w3.org\/2005\/Atom}author at eeba80&gt;,<\/code><br \/>\n<code>&lt;Element {http:\/\/www.w3.org\/2005\/Atom}author at eebba0&gt;]<\/code><\/p>\n<ol>\n<li>\u672c\u4f8b\u4f7f\u7528\u4e86lxml\u5e93<\/li>\n<li>\u8fd9\u4e2a\u67e5\u8be2\u627e\u6240\u6709Atom\u540d\u5b57\u7a7a\u95f4\u7684\u5143\u7d20\uff0c\u5b83\u6709\u4e00\u4e2ahref\u5c5e\u6027\u3002\/\/\u8868\u793a\u65e0\u8bba\u4ec0\u4e48\u6df1\u5ea6\u90fd\u53bb\u627e\u3002{http:\/\/www.w3.org\/2005\/Atom}\u610f\u5473\u7740\u5143\u7d20\u53ea\u5728Atom\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002*\u610f\u5473\u7740\uff1a\u4efb\u610f\u672c\u5730\u540d\u3002[@href]\u610f\u5473\u7740\u6709\u4e00\u4e2ahref\u5c5e\u6027\u3002<\/li>\n<li>\u67e5\u627e\u6240\u6709Atom\u540d\u5b57\u7a7a\u95f4\u7684\u5143\u7d20\uff0chref\u7684\u503c\u662f<code>http:\/\/diveintomark.org\/<\/code>\u3002<\/li>\n<li>After doing some quick string formatting (because otherwise these compound queries get ridiculously long),<br \/>\nthis query searches for Atom author elements that have an Atom uri element as a child. This only returns<br \/>\ntwo author elements, the ones in the first and second entry. The author in the last entry contains only a<br \/>\nname, not a uri.<\/li>\n<\/ol>\n<p>\u7b97\u4e86\uff0c\u4e0d\u770b\u8fd9\u7ae0\u4e86\uff0cXML\u73b0\u5728\u6211\u8fd8\u7528\u4e0d\u5230\uff0c\u4ee5\u540e\u80fd\u7528\u5230\u7684\u65f6\u5019\u518d\u770b\u5427\uff01\u5e94\u8be5\u770b12.7\u8282\u4e86\uff0c\u8bb0\u5f55\u4e00\u4e0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uff081\uff09XML\u662f\u4e00\u79cd\u63cf\u8ff0\u5c42\u6b21\u7ed3\u6784\u6570\u636e\u7684\u901a\u7528\u65b9\u6cd5\u3002\u4e00\u4e2aXML\u6587\u4ef6\u5305\u542b\u4e86\u4e00\u4e2a\u6216\u591a\u4e2aelement\uff0c\u5b83\u88ab\u9650\u5b9a\u5728\u4e00\u5bf9tag\u4e2d\u3002 &lt;foo&gt; \u2460 &lt;\/fo&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=195\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-dive-into-python3"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":10,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":200,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/200"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}