简体   繁体   中英

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. 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.

As an example in this XML the value of email is null not an empty string. 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. If instead we use a space as <email> </email> , the value is getting replaced correctly with what we are replacing.

Any help will be appreciated!

XPath expressions ending in text() cannot match an empty node, because there is no text node inside it. However, for the "Modify text files with regular expressions" action this would indeed be very useful. We have implemented this for 6.1.4. Please contact support@ej-technologies.com to a build where this already works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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