[英]PHP XML DOM: working with a subsection of an xml document
所以我對使用PHP的XML DOM很新。 但是我在以下問題中遇到了麻煩。 所以想象一下,我有一個帶有幾個重復部分的xml文檔,可以按日期區分。 我試圖按日期訪問特定部分,然后使用傳統DOM方法訪問該部分中的數據。 這就是我目前正在做的事情。
XML文檔
<quizzes>
<quiz>
<date>Yesterday</date>
<question>This is the day's question</question
</quiz>
<quiz>
<date>Today</date>
<question>This is the day's question</question
</quiz>
<quiz>
<date>Tomorrow</date>
<question>This is the day's question</question
</quiz>
</quizzes
PHP代碼
$xmlDoc = new DOMDocument()
$xmlDoc->load($aboveXMLFile)
$subSection = $xmlDoc->getElementsByTagName("quiz")->item(0)
$dateofSubSection = $subSection->getElementsByTagName("date")->item(0)->nodeValue;
echo $dateofSubSection
我收到一條錯誤,指出getElementsbyTagName
不是$subSection
的有效方法。 為什么? 如果我不能這樣做,如何按日期選擇子節,然后單獨訪問該子節中的nodeValues?
謝謝你的幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.