2014-09-25 65 views
1

考慮從SVN XML輸出以下(通過svn日誌--xml)信息:使用xmlstarlet解析出修訂和文件從SVN XML輸出

<?xml version="1.0"?> 
<log> 
    <logentry revision="111802"> 
    <author>author1</author> 
    <date>2014-09-24T17:48:11.447209Z</date> 
    <paths> 
     <path kind="file" action="A">/project/trunk/subdir/TransactionInfo.java</path> 
     <path kind="file" action="A">/project/trunk/subdir/Validation.java</path> 
    </paths> 
    <msg>added the start to the new Validation tool </msg> 
    </logentry> 
    <logentry revision="111801"> 
    <author>author2</author> 
    <date>2014-09-24T17:32:51.129605Z</date> 
    <paths> 
     <path kind="file" action="A">/project/dispatcher/branches/EUROPA/docs/somefile.txt</path> 
     <path kind="file" action="A">/project/dispatcher/branches/EUROPA/docs/plans.txt</path> 
    </paths> 
    <msg>add plan steps doc and jobs spreadsheet</msg> 
    </logentry> 
</log> 

我試圖產生輸出這樣的事情。請注意,正確的修訂版本中列出了正確的2個文件。

111802 | author1 | 2014-09-24T17:48:11.447209Z | added the start to the new Validation tool 
    /project/trunk/subdir/TransactionInfo.java 
    /project/trunk/subdir/Validation.java 

111801 | author2 | 2014-09-24T17:32:51.129605Z | add plan steps doc and jobs spreadsheet 
    /project/dispatcher/branches/EUROPA/docs/somefile.txt 
    /project/dispatcher/branches/EUROPA/docs/plans.txt 

我使用下面的命令,而是從兩個版本獲取所有文件。我相信我的錯誤在第二個-m參數中?

xmlstarlet sel -T -t -m /log/logentry -v "concat(@revision,' | ',author,' | ',date,' | ',msg)" -n -m /log/logentry/paths -v "path" -n svnoutput.xml 

111802 | author1 | 2014-09-24T17:48:11.447209Z | added the start to the new Validation tool 
/project/trunk/subdir/TransactionInfo.java 
/project/trunk/subdir/Validation.java 
/project/dispatcher/branches/EUROPA/docs/somefile.txt 
/project/dispatcher/branches/EUROPA/docs/plans.txt 
111801 | author2 | 2014-09-24T17:32:51.129605Z | add plan steps doc and jobs spreadsheet 
/project/trunk/subdir/TransactionInfo.java 
/project/trunk/subdir/Validation.java 
/project/dispatcher/branches/EUROPA/docs/somefile.txt 
/project/dispatcher/branches/EUROPA/docs/plans.txt 

作爲一個側面說明以爲我會分享,這將產生一個新的總結,我發現非常有用:

xmlstarlet sel -T -t -m /log/logentry -v "concat(@revision,' | ',author,' | ',date,' | ',msg)" -n svnoutput.xml 

111802 | author1 | 2014-09-24T17:48:11.447209Z | added the start to the new Validation tool 
111801 | author2 | 2014-09-24T17:32:51.129605Z | add plan steps doc and jobs spreadsheet 

回答

1

剛剛擺脫的額外-m和你的第二個值更改爲paths/path

xmlstarlet sel -T -t -m /log/logentry 
        -v "concat(@revision,' | ',author,' | ',date,' | ',msg)" 
        -n 
        -v "paths/path" 
        -n svnoutput.xml 
+0

很好,謝謝! – patterson7019 2014-09-26 15:21:05