Maven ant regex 插入 XML 文本



我正在尝试通过 maven ant 插件和 replaceregexp 任务将 xml 元素插入到 xml 文件中。

这是它最初的样子:

  <types>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/c/data/v4_6'
       schemaLocation='commoncomplexelements.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/b/data/v1_5'
       schemaLocation='location.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/location/a/data/v1_5'
       schemaLocation='location-validcodes.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
       schemaLocation='oasis-200401-wss-wssecurity-secext-1.0.xsd' />
    </xs:schema>  
  </types>

这就是它最终应该的样子:

  <types>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/c/data/v4_6'
       schemaLocation='commoncomplexelements.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/b/data/v1_5'
       schemaLocation='location.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://biz.funct.com/location/a/data/v1_5'
       schemaLocation='location-validcodes.xsd' />
    </xs:schema>
    <xs:schema>
        <xs:import namespace='http://biz.funct.com/location/d/data/v1_5'
            schemaLocation='newfile.xsd' />
    </xs:schema>
    <xs:schema>
       <xs:import namespace='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
       schemaLocation='oasis-200401-wss-wssecurity-secext-1.0.xsd' />
    </xs:schema>  
  </types>

这是我到目前为止所拥有的:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <id>insert-xml</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target name="Insert xml">
                            <replaceregexp flags="m">
                              <regexp pattern="&lt;xs:schema&gt;(.*)&lt;/xs:schema&gt;"/>
                              <substitution expression="hello"/>
                              <filelist 
                                  id="" 
                                  dir="${project.build.directory}/f"
                                  files="ServiceInterface.wsdl"/> 
                            </replaceregexp>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

任何帮助获得正确的正则表达式将不胜感激。

您可以

尝试(?=<xs:schema>(?:(?!</xs:schema>).)+</xs:schema>s*</type‌​s>) regex101.com/r/letGLw/2,只需将"match"(零宽度 - 仅位置,由最后一个</types>锚定(替换为替换字符串。

https://regex101.com/r/letGLw/2/

相关内容

  • 没有找到相关文章

最新更新