我想阅读CDATA" Testlabel"来自包含此结构的结构中的入口节点:
<dynamic-element fieldNamespace="ddm" indexType="keyword" localizable="true" name="Label_Tag" readOnly="false" repeatable="false" required="false" showLabel="true" type="ddm-separator" width="">
<meta-data locale="nl_NL">
<entry name="label">
<![CDATA[Testlabel]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
<entry name="style">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
在AssetPublisher的应用程序显示模板中,我使用了:
#foreach ( $entry in $entries )
#set ( $renderer = $entry.getAssetRenderer() )
#set ( $className = $renderer.getClassName() )
#if ( $className == "com.liferay.portlet.journal.model.JournalArticle" )
## read article properties
#set ( $article = $renderer.getArticle() )
## read webcontent as xml
#set ( $document = $saxReaderUtil.read($article.getContent()) )
#set ( $rootElement = $document.getRootElement() )
## read general elements from webcontent
#set ( $xPathSelector = $saxReaderUtil.createXPath("dynamic-element[@name='Label_Tag']/meta-data/entry[@name='label']") )
#set ( $strLabel = $xPathSelector.selectSingleNode($rootElement).getText() )
$ xPathSelector $xPathSelector<br>
$ strLabel $strLabel <br>
#end
#end
不起作用,它打印:
$ xPathSelector [XPath: dynamic-element[@name='Label']/meta-data/entry[@name='label']]
$ strLabel $strLabel
$ strLabel未填写。有什么不对?
答案 0 :(得分:0)
你的XPath表达是正确的;当使用div
将其应用于您的样本时,我得到以下结果:
xmllint
也许在XPath查询中添加> xmllint -xpath "dynamic-element[@name='Label_Tag']/meta-data/entry[@name='label']" ~/test.xml
<entry name="label">
<![CDATA[Testlabel]]>
</entry>
可能有所帮助:
text()