如何使用不在父,构建或依赖性标签中的powershell中提取pom.xml中的artrifactid
我有以下pom.xml文件,我只想阅读以下伪像数据,而忽略了使用PowerShell Regex Match在下面的标签和标签之间的伪影信息,
**<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description**>
<modelVersion>4.5.0</modelVersion>
<parent>
<groupId>com.frt</groupId>
<artifactId>parent-pom</artifactId>
<version>2.0.0</version>
</parent>
<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.tools.maven</groupId>
<artifactId>maven-plugin</artifactId>
<configuration>
<classifier>application</classifier>
</configuration>
</plugin>
<plugin>
<groupId>com.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<configuration>
<runtimeProduct>4.5.0</runtimeProduct>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>9072cf0-111fc2b0fae6</groupId>
<artifactId>json-logger</artifactId>
<classifier>mulr-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mul2.connectors</groupId>
<artifactId>mul2-http-connector</artifactId>
<classifier>mul2-plugin</classifier>
</dependency>
我尝试过,它给出了所有伪像的名称,我不确定如何获得我想要的方式,
Get-Content pom.xml -Raw | % { [regex]::matches($_ , '<artifactId>([\s\S]*?)</artifactId>')} |% {$_.Groups[1].Value}
将不胜感激
I have the below pom.xml file and i want to read only below artifact data and ignore the artifact info that are in between the and tags using powershell regex match
**<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description**>
<modelVersion>4.5.0</modelVersion>
<parent>
<groupId>com.frt</groupId>
<artifactId>parent-pom</artifactId>
<version>2.0.0</version>
</parent>
<groupId>com.frt</groupId>
<artifactId>documents-v1</artifactId>
<version>2.0.3</version>
<packaging>application</packaging>
<name>documents</name>
<description>To raise a client request </description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.tools.maven</groupId>
<artifactId>maven-plugin</artifactId>
<configuration>
<classifier>application</classifier>
</configuration>
</plugin>
<plugin>
<groupId>com.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<configuration>
<runtimeProduct>4.5.0</runtimeProduct>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>9072cf0-111fc2b0fae6</groupId>
<artifactId>json-logger</artifactId>
<classifier>mulr-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mul2.connectors</groupId>
<artifactId>mul2-http-connector</artifactId>
<classifier>mul2-plugin</classifier>
</dependency>
Below is what i tried and its giving all the artifact names, i am not sure how to get the way i want it
Get-Content pom.xml -Raw | % { [regex]::matches($_ , '<artifactId>([\s\S]*?)</artifactId>')} |% {$_.Groups[1].Value}
Any help would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正则是最后的手段。 PowerShell可以为您解析XML!
而是尝试一下:
这个^对我失败了,因为我认为您没有在问题中包含XML文件的全部内容。
在这里,您会发现您的财产和下一个“点”。如果建造是属性,则...
冲洗并重复
Regex is a last resort. PowerShell can parse XML for you!
Try this instead:
This^ failed for me because I assume you did not include the entire contents of the XML file in your question.
After here you would find your property and next "dot" into it. If build was the property then...
Rinse and repeat