[英]JAXB Parsing an XML file with variables (e.g. $(var1) )
I'm interested to parse an XML that contains variables (which are defined by me inside the XML). 我对解析包含变量的XML(由我在XML内部定义)感兴趣。
Here's an example of the XML files: 这是XML文件的示例:
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
<Parents>
<Parent id="$(parent-id)">
<Children>
<Child id="$(child-id)">
</Child>
</Children>
</Parent>
</Parents>
Is there a utility or some standard way to do so in Java? 在Java中是否有实用程序或某种标准方法可以做到这一点? (using JAXB possibly) Or should I implement this "mini" parsing mechanism by myself?
(可能使用JAXB)还是我应该自己实现这种“小型”解析机制? (A mechanism that identifies the variables and plants them inside the XML, and only later calls JAXB flows)
(一种识别变量并将其植入XML的机制,以后仅调用JAXB流)
Thanks a lot in advance! 在此先多谢!
Use an XSLT transformation to convert your XML into an XSLT stylesheet and then execute the XSLT stylesheet. 使用XSLT转换将XML转换为XSLT样式表,然后执行XSLT样式表。 It's simple enough to convert
转换非常简单
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
into 成
<xsl:param name="parent-id" select="1" />
<xsl:param name="child-id" select="1" />
and 和
<Parent id="$(parent-id)">
into 成
<Parent id="{$parent-id}">
and to add a wrapper xsl:stylesheet
and xsl:template
element, and then you're done. 并添加包装器
xsl:stylesheet
和xsl:template
元素,然后就可以完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.