简体   繁体   English

JAXB解析带有变量的XML文件(例如$(var1))

[英]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:stylesheetxsl:template元素,然后就可以完成。

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

相关问题 使用JAXB Marshaller处理XML转义字符(例如引号) - Handling XML escape characters (e.g. quotes) using JAXB Marshaller 使用 JAXB 解析 xml 文件 - Parsing xml file with JAXB 使用JAXB Marshaller转义字符(例如引号) - escape characters (e.g. quotes) using JAXB Marshaller Selenium Webdriver:是否可以检查资源(例如XML文件)是否已加载? - Selenium webdriver: can I check if a resource (e.g. XML file) has been loaded? 使用JAXB将XML解析为Java变量(beans) - parsing XML to java variables(beans) using JAXB 访问元素标签以获取重复的子规则; 例如,使用ANTLR解析“ a IN(1、2、3)” - Accessing element labels for repeated subrules; e.g. parsing “a IN (1, 2, 3)” with ANTLR 为什么必须用值初始化某些变量(例如0,null)? - Why must some variables be initialized with a value (e.g. 0, null)? 在Java Servlet中使用静态变量(例如在AppEngine中) - Usage of Static variables in Java Servlets (e.g. in AppEngine) 可配置(例如XML)的Java Bean到Bean映射框架 - Configurable (e.g. XML) Java Bean to Bean Mapping Framework JAXB:如果有特殊值(例如`null`或`Double.NaN`),则忽略元素序列化 - JAXB: ignore element serialization in case of special value (e.g. `null` or `Double.NaN`)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM