xpath - print text inside <project><groupId>..</groupId> and <project><parent><groupId>..</groupId> -


i need list text inside these 2 elements in many pom.xml in directory tree. files may contain element @ other places too, looking content of these two.

ideally, looking tool outputs in format <file-name>:<line-no>:<path>:<text>, e.g.

parent/pom.xml:12:/project/groupid:com.acme.project features/persist/pom.xml:14:/project/parent/groupid:com.acme.project features/persist/pom.xml:32:/project/groupid:com.acme.project.persist 

for following input files:

**parent/pom/xml** <project>  ...   <groupid>   com.acme.project <!--line 12 -->    </groupid> ... </project>  **feature/persist/pom.xml** <project>   <parent>     <groupid>     com.acme.project <!--line 14 -->      </groupid>   </parent>   ...   <groupid>   com.acme.project   </groupid>   <dependencymanagement>     <dependencies>       <dependency>         <groupid>         a.b.c.d <!-- not listed in output -->         </groupid>       </dependency>     </dependencies>   </dependencymanagement> </project> 

note other paths such dependencymanagement/dependencies/dependency/groupid not included.

searching here on came across xmllint --xpath , don't know enough xpath figure out myself.

try xpath 2.0 compatible query without line numbers, checks query paths matching <groupid/> elements , prints document name, constructs (not unique) path , adds contents of element.

(//project/parent | //project)/groupid/string-join(   (     base-uri(),     string-join(('', .//ancestor-or-self::*/name()), '/'),     data(.)   ), ':') 

you run using basex collection example (like did testing), contains xml files want query.

  1. run command create collection: create db xmldocs /path/to/xml-files
  2. query database using above xpath

there different ways run query, have @ standalone mode manual.

the query should run in other xpath 2.0 compatible engines saxon (which support line numbers, see comment above).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -