简体   繁体   English

寻找用于从值/ XPath对列表创建XML文档的Java解决方案

[英]Looking for a Java solution for creating an XML document from a list of value/XPath pairs

I have two columns in a spreadsheet. 我在电子表格中有两列。

One column is an XPath expression used to get a value from an existing XML document. 一列是用于从现有XML文档获取值的XPath表达式。 The other column is an XPath expression from which I need to create my XSLT/output XML document. 另一列是XPath表达式,我需要从中创建我的XSLT /输出XML文档。 The value grabbed from the first column will be the value placed in the second column's element. 从第一列中获取的值将是放置在第二列元素中的值。

So for example if the second column has the XPath /A/B/C, I would create 因此,例如,如果第二列具有XPath / A / B / C,我将创建

<A>
  <B>
    <C><xsl:value-of select = "corresponding value from 1st column"/></C>
  </B>
</A>

If the next XPath is /A/B/D, I would add 如果下一个XPath是/ A / B / D,我会添加

<D><xsl:value-of select = "corresponding value from 1st column"/></D> 

as a sibling of C. 作为C的兄弟姐妹

I'm expected to create this output XML/XSLT structure by hand. 我希望手动创建这个输出XML / XSLT结构。 However there are thousands of lines. 但是有数千行。

I'm looking for suggestions on how to do this programmatically in Java. 我正在寻找有关如何在Java中以编程方式执行此操作的建议。 I've never mixed Java/XML/XPath so maybe there are libraries that can help with this? 我从来没有混合使用Java / XML / XPath所以也许有些库可以帮助解决这个问题? If it's an enormous undertaking I won't be able to justify it as opposed to just doing it by hand. 如果这是一项艰巨的任务,我将无法证明这一点,而不是仅仅手工完成。 If I can write something that gets me most of the way there I'd be happy. 如果我能写出能让我大部分时间到处都能找到的东西,我会感到高兴。 Is this a pipe dream? 这是个梦想吗?

Sure, most Java XML libraries support retrieving DOM nodes via XPath quite painlessly. 当然,大多数Java XML库都支持通过XPath轻松地检索DOM节点。 Often they use Jaxen as their backend, so make sure you have the Jaxen JAR in your class path. 他们通常使用Jaxen作为后端,因此请确保在类路径中使用Jaxen JAR。 See XPath support in JDOM , DOM4J , and XOM . 请参阅JDOMDOM4JXOM中的 XPath支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM