简体   繁体   English

使用regex和xpath表达式Install4j更新XML文件

[英]Install4j Update XML file using regex and xpath expression

When writing a value to a XML file using install4j if we encounter an empty XML node element, the value is not written to the the file, because either the xpath expression is not correct or the regex cannot match the empty node value. 如果我们遇到一个空的XML节点元素,使用install4j将值写入XML文件时,该值不会写入该文件,因为xpath表达式不正确或正则表达式与空节点值不匹配。 Can any one explain what we need to do in such a case? 任何人都可以解释在这种情况下我们需要做什么吗? Is there a regex to match empty node value? 是否有正则表达式匹配空节点值? So that correct value gets replaced. 这样就可以替换正确的值。 Or Xpath expression needs to be updated to match empty node value. 或者需要更新Xpath表达式以匹配空节点值。

As an example in this XML the value of email is null not an empty string. 作为此XML中的示例,email的值为null而不是空字符串。 So how do we match the expression so that value gets replaced correctly. 那么我们如何匹配表达式以便正确地替换值。

    <?xml version="1.0"?>
    <Employees>
        <Employee emplid="1111" type="admin">
            <firstname>John</firstname>
            <lastname>Watson</lastname>
            <age>30</age>
            <email></email>
        </Employee>
    </Employees>

在此输入图像描述

The result when using install4j is that the XML file gets updated from <email></email> to </email> which is because the null node value is not getting replaced. 使用install4j时的结果是XML文件从<email></email></email> ,这是因为空节点值未被替换。 If instead we use a space as <email> </email> , the value is getting replaced correctly with what we are replacing. 相反,如果我们使用空格作为<email> </email> ,则值将被替换为正确替换。

Any help will be appreciated! 任何帮助将不胜感激!

XPath expressions ending in text() cannot match an empty node, because there is no text node inside it. 以text()结尾的XPath表达式与空节点不匹配,因为其中没有文本节点。 However, for the "Modify text files with regular expressions" action this would indeed be very useful. 但是,对于“使用正则表达式修改文本文件”操作,这确实非常有用。 We have implemented this for 6.1.4. 我们已经为6.1.4实现了这一点。 Please contact support@ej-technologies.com to a build where this already works. 请联系support@ej-technologies.com到已经有效的版本。

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

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