0
我有下面的XML文檔:找不到Atom的節點使用Ruby的libxml
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:apps=\"http://schemas.google.com/apps/2006\" xmlns:gd=\"http://schemas.google.com/g/2005\">
<apps:property name=\"memberId\" value=\"Tom\"/>
</atom:entry>
所有我想要做的就是將應用程序:屬性節點。然而,我在LibXML中嘗試的所有內容都沒有返回。
從閱讀LibXML文檔here獲取LibXML :: XML :: XPath。我假設我不需要指定兩個名稱空間,因爲它們是在根節點上定義的。
這裏是我試過:
@document.find('/apps:property')
@document.find('//apps:property')
@document.find('/atom:entry/apps:property')
@document.find('//atom:entry/apps:property')
@document.find('/property')
@document.find('/atom:entry')
@document.find('//property')
@document.find('/entry')
以上都不對返回的結果與指定的文檔。我已經用原子和應用程序命名空間定義的不同組合來嘗試它們,但它似乎沒有效果。
如果有人能告訴我什麼是非常簡單的事情,我必須錯過它將不勝感激。
事實證明,問題源於動態創建的文檔,而不是從文件讀取。
當我將文檔寫入文件並讀取它時,我可以搜索它。當我創建文檔時,創建根元素並以編程方式添加子項,每次嘗試搜索時都會得到零,奇怪的是,每項工作都很好。在搜索之前,我是否必須「確定」或者以某種方式對文檔做一些其他愚蠢的事情?