English 中文(简体)
整块xml树结构
原标题:xpath to get the entire xml tree structure

是否有办法利用Xpath获得整个树木结构。 例如,这就是说

<a>
   <b>
      <c>
         data
      </c>
   </b>
</a>

我想先谈一下 no子的所有内容,结果应该是

  <b>
     <c>
        data
     </c>
  </b>

迄今为止,我一直在使用VTD-XML和java来检索这些内容。 这是我使用的法典。

    VTDGen vg = new VTDGen();
    vg.setDoc(xmlString);
    vg.parse(true);
    VTDNav vn = vg.getNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath(xPath);
    String data = ap.evalXPathToString();
问题回答

记住XPath选择了一个节点或一套节点。 想把它作为回归点,投入你原来的树木。 它不归还“整个树木结构”,而是把点击点推到该结构中选定的节点。 不管你选择什么,整个结构都可以通过从选定的节点到其他人来获得。 这种导航可以使用进一步的XPath型表述,也可以使用类似于DOM的导航标本,也可以通过诸如序列化等行动(通常在你序列号时,显示位于该代号的整子树)。

<>Use:

/*/node()

这选择了《少年犯罪法》文件最主要内容的所有儿童节点。 由于每个选定要素都保留整个子树(其中这一要素是上层)。

<>XSLT”为基础的核查:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/">
  <xsl:copy-of select="/*/node()"/>
 </xsl:template>
</xsl:stylesheet>

当这一转变适用于XML文件时:

<a>
  <b>
     <c>
      data
     </c>
  </b>
</a>

XPath expression is evaluation and the selected nodes areproduct, Production the commission, right:

<b>
   <c>
      data
     </c>
</b>

理想的情况是,“/b”从目前与选择相对应的节点中选择了节点。

用途

/descendant-or-self::node()




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签