2017-09-13 7 views
0

지정한 태그가 포함 된 XML 파일의 모든 섹션을 추출하려고합니다. 나는 웹을 검색하고 이것이 작동하는 것을 발견했다.xmllint를 사용하여 여러 결과 반환

xmllint --xpath "/all/string(//title)" 

그러나 첫 번째 결과 만 반환합니다. 어떻게 모든 결과를 찾을 수 있습니까? 감사!

샘플 XML

<programme start="20170913125500 +0100" stop="20170913144500 +0100" channel="3b6963d34ba31ea21db5c3aee8e3b26f"> 
    <title lang="eng">Yangtse Incident</title> 
    <sub-title lang="eng">(1957) Michael Anderson&apos;s drama, starring Richard Todd and William Hartnell, tells the true story of HMS Amethyst, a British frigate captured by Chinese communists during Mao&apos;s revolution. [AD,S]</sub-title> 
</programme> 
<programme start="20170913144500 +0100" stop="20170913165500 +0100" channel="3b6963d34ba31ea21db5c3aee8e3b26f"> 
    <title lang="eng">The Comancheros</title> 
    <sub-title lang="eng">(1961) Western starring John Wayne and Stuart Whitman. A Texas Ranger is forced to team up with his prisoner while he&apos;s on a covert mission to take on a band of thieves and gunrunners. [S]</sub-title> 
</programme> 
<programme start="20170913165500 +0100" stop="20170913185500 +0100" channel="3b6963d34ba31ea21db5c3aee8e3b26f"> 
    <title lang="eng">The Cockleshell Heroes</title> 
    <sub-title lang="eng">(1955) World War II drama. In a true-life tale of incredible bravery, ten marines try to break the blockade of Bordeaux. With José Ferrer, Trevor Howard, Victor Maddern and Anthony Newley. [S]</sub-title> 
</programme> 
<programme start="20170913185500 +0100" stop="20170913190500 +0100" channel="3b6963d34ba31ea21db5c3aee8e3b26f"> 
    <title lang="eng">Dunkirk Interview Special</title> 
    <sub-title lang="eng">Stars Harry Styles, Mark Rylance, Jack Lowden, Fionn Whitehead and Tom Glynn-Carney talk about making director Christopher Nolan&apos;s intense Second World War dramatic thriller. [S]</sub-title> 
</programme> 

결과 나는 그것이 당신이 그것을 원하는 방식으로 단지 xmllint가 함께 작동하도록 얻을 수 없었다

Yangtse Incident 
The Comancheros 
The Cockleshell Heroes 
Dunkirk Interview Special 
+0

는 당신이에 시도하는 샘플'XML'를 제공 할 수 사용할 수 있습니다? – Inian

+0

샘플 XML을 원래 게시물에 추가 했으므로 코멘트로 추가 할 문자가 너무 많습니다. – user2679016

답변

0

해야한다. 가장 가까운 값은 다음과 같습니다.

xmllint --xpath "//something/programme/title/text()" test.xml 

그러나 이렇게하면 모든 출력이 한 줄로 표시됩니다. 물론

xmllint --xpath "//something/programme/title" test.xml | sed 's/<\/title>/\n/g' | sed 's/<title lang="eng">//g' 

당신이 출력을 정리하기 위해 다른 도구를 사용할 수 있습니다

나를 위해 가장 좋은 방법은이이었다. 대신 xmllint가의 xmlstarlet을 사용 할 수 있다면

0

, 당신은이 sel (select) command ...

==> xml sel -t -m "//programme/title" -v . -n input.xml 
Yangtse Incident 
The Comancheros 
The Cockleshell Heroes 
Dunkirk Interview Special