在下面的XML片段...如何從XML文件中提取與其他字符串共享相同標記的特定字符串?
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xml" href="/static/atom.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:s="http://dev.splunk.com/ns/rest" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<title>serverclients</title>
<id>https://splfwdprw2:8089/servicesNS/nobody/search/deployment/server/clients</id>
<updated>2017-04-04T16:14:04-04:00</updated>
<generator build="f3e41e4b37b2" version="6.3.1"/>
<author>
<name>Splunk</name>
</author>
<link href="/servicesNS/nobody/search/deployment/server/clients/_acl" rel="_acl"/>
<link href="/servicesNS/nobody/search/deployment/server/clients/countClients_by_machineType" rel="countClients_by_machineType"/>
<link href="/servicesNS/nobody/search/deployment/server/clients/countRecentDownloads" rel="countRecentDownloads"/>
<link href="/servicesNS/nobody/search/deployment/server/clients/getMatchingAppsForClient_dryRun" rel="getMatchingAppsForClient_dryRun"/>
<link href="/servicesNS/nobody/search/deployment/server/clients/preview" rel="preview"/>
<opensearch:totalResults>1</opensearch:totalResults>
<opensearch:itemsPerPage>18446744073709551615</opensearch:itemsPerPage>
<opensearch:startIndex>0</opensearch:startIndex>
<s:messages/>
<entry>
<title>00031e8f6c883544b8079037c5eba9ec</title>
<id>https://splfwdprw2:8089/servicesNS/nobody/search/deployment/server/clients/00031e8f6c883544b8079037c5eba9ec</id>
<updated>2017-04-04T16:14:04-04:00</updated>
<link href="/servicesNS/nobody/search/deployment/server/clients/00031e8f6c883544b8079037c5eba9ec" rel="alternate"/>
<author>
<name>system</name>
</author>
<link href="/servicesNS/nobody/search/deployment/server/clients/00031e8f6c883544b8079037c5eba9ec" rel="list"/>
<link href="/servicesNS/nobody/search/deployment/server/clients/00031e8f6c883544b8079037c5eba9ec" rel="remove"/>
<content type="text/xml">
<s:dict>
<s:key name="applications">
<s:dict>
<s:key name="all_deploymentclient">
<s:dict>
<s:key name="action">Phonehome</s:key>
<s:key name="archive">/opt/splunk/var/run/tmp/all_deploymentclient/all_deploymentclient-1491320471.bundle</s:key>
<s:key name="checksum">0</s:key>
<s:key name="excludeFromUpdate"></s:key>
<s:key name="failedReason"></s:key>
<s:key name="issueReload">0</s:key>
<s:key name="restartSplunkWeb">0</s:key>
<s:key name="restartSplunkd">1</s:key>
<s:key name="result">Ok</s:key>
<s:key name="serverclasses">
<s:list>
<s:item>all_deploymentclient</s:item>
</s:list>
</s:key>
<s:key name="size">10240</s:key>
<s:key name="stateOnClient">enabled</s:key>
<s:key name="timestamp">Tue Apr 4 11:42:54 2017</s:key>
</s:dict>
</s:key>
<s:key name="all_fwd_outputs_18indexers">
<s:dict>
<s:key name="action">Phonehome</s:key>
<s:key name="archive">/opt/splunk/var/run/tmp/all_fwd/all_fwd_outputs_18indexers-1491320471.bundle</s:key>
<s:key name="checksum">0</s:key>
<s:key name="excludeFromUpdate"></s:key>
<s:key name="failedReason"></s:key>
<s:key name="issueReload">0</s:key>
<s:key name="restartSplunkWeb">0</s:key>
<s:key name="restartSplunkd">1</s:key>
<s:key name="result">Ok</s:key>
<s:key name="serverclasses">
<s:list>
<s:item>all_fwd</s:item>
</s:list>
</s:key>
<s:key name="size">10240</s:key>
<s:key name="stateOnClient">enabled</s:key>
<s:key name="timestamp">Tue Apr 4 11:42:54 2017</s:key>
</s:dict>
</s:key>
...我試圖提取任何「S:鍵名=」出現在下面的第一級字符串「S:鍵名=」應用程序「標籤,在這個例子中,我想要提取的字符串是」all_deploymentclient「和」all_fwd_outputs_18indexers「,如果額外的字符串出現在同一級別,我想要捕獲這些字符串。我正在使用xml_grep,但我不確定如何定義參數以獲得所需的結果(因爲有多個「s:key name =」標記的實例,其中一些實例可用作標題和有價值的其他人分配給他們)。
所以,當這一切都說過和做過,提取輸出這個例子應該是:
all_deploymentclient
all_fwd_outputs_18indexers
我怎樣才能做到這一點?是否需要另一個實用工具(如xpath)?
「XML片段」是否完整?前綴's'是否在任何地方? (像'xmlns:s =「一些命名空間uri」'。) –