English 中文(简体)
xpath expression for child elements
原标题:xpath expression for child elements
  • 时间:2012-05-09 14:46:03
  •  标签:
  • xpath

我有这种类型的xml文档。

 <a Text="">
   <b>
     <c Text=""/>
     < c Text=""/>
   </b>
    <b>
          <c/>
    </b>
 </a>

因此,我需要像产出那样的产出。

     a
        c
        c

您能帮助我撰写这篇论文吗? 我需要忽视。

问题回答

假定你想要选择一个节点和节点,你可以使用这一表述:

/a | /a/b/c

这将选择所有节点和节点。 请注意,本文件仅将按规定级别选择这些文件。 你们也可以做这样的事情:

//a | //c

难道你能够让我们更多地了解这一提问的目的吗?

你们也可以这样做:

<div class="breadcrumb">
{
for $d in doc("test.xml")/a/b/c return
<a href="somepage.php?id={fn:data($d/@Text)}">{fn:data($d/@Text)}</a>
}
</div>

目 录

<a>
  <b>
    <c Text="Cat1" />
    <c Text="Cat2" />
    <c Text="Cat3" />
  </b>
  <b>
    <c Text="Cat4" />
    <c Text="Cat5" />
  </b>
</a>

您将获得这一产出:

<div class="breadcrumb">
    <a href="somepage.php?id=Cat1">Cat1</a>
    <a href="somepage.php?id=Cat2">Cat2</a>
    <a href="somepage.php?id=Cat3">Cat3</a>
    <a href="somepage.php?id=Cat4">Cat4</a>
    <a href="somepage.php?id=Cat5">Cat5</a>
</div>




相关问题
VTD XML inner XPath Expressions

I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test&...

C# XML adding/copying

With the following XML I am trying to copy and add to another XML but I haven t used the C# XML document objects before. So here is the XML <config> <configXML> <Connections&...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don t know why =S import libxml2, ...

热门标签