XML 读出嵌套内容
XML Reading out Nested Content
假设我有以下结构
<xmlsheet>
<someContent>
<directContent>hello</directContent>
<otherDirectContent>hello again</otherDirectContent>
<nestedContent>
<title>Hello im a Title</title>
</nestedContent>
</someContent>
<someOtherContent></someOtherContent>
</xmlsheet>
如何 select someContent 中 nestedContent 的标题?
当我 select someContent 中的 directContent 时,它是这样工作的
<cms:contentaccess var="content" />
<c:set var="directContent" value="${content.valueList.someContent[0].value.directContent}"/>
如果我只说 ${content.valueList.someContent[0].value}
它会抛出直接和 otherDirect 内容,但不会抛出嵌套内容:<
此代码 ${content.valueList.someContent[0].value['nestedContent/title']
有效。它使用值的 xpath。
来自 documentation
Map:getValue()
Returns a lazy initialized Map that provides values from the XML content in the current locale. The provided Map key is assumed to be a String that represents the xpath to the value.
另请参阅底层 Java API
假设我有以下结构
<xmlsheet>
<someContent>
<directContent>hello</directContent>
<otherDirectContent>hello again</otherDirectContent>
<nestedContent>
<title>Hello im a Title</title>
</nestedContent>
</someContent>
<someOtherContent></someOtherContent>
</xmlsheet>
如何 select someContent 中 nestedContent 的标题?
当我 select someContent 中的 directContent 时,它是这样工作的
<cms:contentaccess var="content" />
<c:set var="directContent" value="${content.valueList.someContent[0].value.directContent}"/>
如果我只说 ${content.valueList.someContent[0].value}
它会抛出直接和 otherDirect 内容,但不会抛出嵌套内容:<
此代码 ${content.valueList.someContent[0].value['nestedContent/title']
有效。它使用值的 xpath。
来自 documentation
Map:getValue()
Returns a lazy initialized Map that provides values from the XML content in the current locale. The provided Map key is assumed to be a String that represents the xpath to the value.
另请参阅底层 Java API