2
我對PowerShell並不陌生,但我正在進行XML解析。基本上我想從OPF文件中提取標題,創建者和發佈者信息,這只是一個xml文件。下面這本書是Google的epub v3樣本集合中的Moby Dick。如何使用PowerShell來提取Epub元數據(XML)?
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="pub- id" prefix="cc: http://creativecommons.org/ns#">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Moby-Dick</dc:title>
<meta refines="#title" property="title-type">main</meta>
<dc:creator id="creator">Herman Melville</dc:creator>
<meta refines="#creator" property="file-as">MELVILLE, HERMAN</meta>
<meta refines="#creator" property="role" scheme="marc:relators">aut</meta>
<dc:identifier id="pub-id">code.google.com.epub-samples.moby-dick-basic</dc:identifier>
<dc:language>en-US</dc:language>
<meta property="dcterms:modified">2012-01-18T12:47:00Z</meta>
<dc:publisher>Harper & Brothers, Publishers</dc:publisher>
<dc:contributor id="contrib1">Dave Cramer</dc:contributor>
<meta refines="#contrib1" property="role" scheme="marc:relators">mrk</meta>
<dc:rights>This work is shared with the public using the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) license.</dc:rights>
<link rel="cc:license" href="http://creativecommons.org/licenses/by-sa/3.0/"/>
<meta property="cc:attributionURL">http://code.google.com/p/epub-samples/</meta>
</metadata>
</package>
我已經試過:
[xml]$opf = gc path/to/package.opf
$opf.package.metdata
我只抽到了標籤,並與此,而不是文本屬性信息。
哈啊,所以這就是它是如何工作。你有什麼文章可以參考這些信息嗎?我想知道更多關於如何工作。 –
另外,如何獲得標籤的文本,即 MELVILLE,HERMAN? –
沒關係,我想我可以像這樣做$ opf.package.metadata.meta | %{$ _。 '#文字'}。謝謝你的幫助Magnus。 –