Ich habe ein XML-Dokument, das Ausführungsinformationen zu meiner Anwendung enthält. Ich möchte spezifische XML-Elemente basierend auf der gegebenen Bedingung erhalten.So erhalten Sie ein bestimmtes Element in XML, das den Standardnamespace enthält, basierend auf der Bedingung mit XPath
Für ex:
XML-Dokument:
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:sop='http://www.hp.com/dma/api/sop'>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61</id>
<author><name>HP DMA</name></author>
<updated>2016-10-07T07:19:12Z</updated>
<title>H_ARG_C_02200_Patch_MSSQl_Instances</title>
<link rel='self' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/workflow/view/8618f087562b59f00156bc297a3d3ab9' />
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e0297417b74</id>
<published>2016-10-07T07:19:12Z</published>
<updated>2016-10-07T07:20:13Z</updated>
<title>MS SQL - Parameters - Install Patch</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e0297417b74' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f0875360c19b015360cf31b72f4c' />
<sop:status state='Finished' rc='0'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03858e7b95</id>
<published>2016-10-07T07:20:13Z</published>
<updated>2016-10-07T07:20:26Z</updated>
<title>MS SQL - Advanced Parameters - Install Patch</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03858e7b95' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f0875360c19b015360cf55ae32e4' />
<sop:status state='Finished' rc='0'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03b9e97ba2</id>
<published>2016-10-07T07:20:26Z</published>
<updated>2016-10-07T07:20:43Z</updated>
<title>Check If Download File Exists</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03b9e97ba2' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f0875360c19b015360ce1ffc162d' />
<sop:status state='Finished' rc='2'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03fd0c7c2b</id>
<published>2016-10-07T07:20:44Z</published>
<updated>2016-10-07T07:23:38Z</updated>
<title>Download Software</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e03fd0c7c2b' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f087535fbe2a01535fbe3cd80002' />
<sop:status state='Finished' rc='0'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e06a8887e5b</id>
<published>2016-10-07T07:23:39Z</published>
<updated>2016-10-07T07:24:00Z</updated>
<title>MSSQL Check Build of Patch File</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e06a8887e5b' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f0875360c19b015360cf38dd300c' />
<sop:status state='Finished' rc='1'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e06fe117f22</id>
<published>2016-10-07T07:24:00Z</published>
<updated>2016-10-07T07:24:12Z</updated>
<title>Delete File</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e06fe117f22' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/8618f0875360c19b015360cc72f90321' />
<sop:status state='Finished' rc='0'/>
</entry>
<entry>
<id>https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e072e927f2f</id>
<published>2016-10-07T07:24:13Z</published>
<updated>2016-10-07T07:24:13Z</updated>
<title>Failure</title>
<link rel='alternate' type='application/atom+xml' href='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/step/8618f087562b59f001579e072e927f2f' />
<link rel='alternate' type='text/html' href='https://6.152.112.7:8443/dma/sop/step/view/5e844d3e7a134731a64fbcba727b673f' />
<sop:status state='Finished' rc='0'/>
</entry>
<sop:target server='Win8R2MSSQL-1' instance='MSSQLSERVER' />
<sop:script-execution url='https://6.152.112.7:8443/dma/api/auto/running/workflow/8618f087562b59f001579e0296227b61/scriptExecution/8618f087562b59f001579e0298de7b91'/>
<sop:status state='Failed'/>
<sop:deployment name='H_ARG_C_02200_Patch_MSSQL_Instances_Deployment'/>
</feed>
Über XML enthält eine Liste von <entry>
Elemente, die einige Informationen jeder Ausführungsschritt hat (<entry></entry>
Element enthält Ausführungs Info).
Angenommen, wenn alle "Eintrag" Elemente erhalten möchten, die rc aufweisen, sind = 0.
Für Ex:
<sop:status state='Finished' rc='1'/>
<sop:status state='Finished' rc='2'/>
Dazu verwende ich XPath-Abfrage (siehe unten), aber ich kann nichts bekommen.
/feed/entry/sop:status[@ rc!="0"]
and
//entry/sop:status[@ rc!="0"]
Ist dies der richtige Weg, XML zu parsen, kann jemand dabei helfen?
von oben XPath, kann ich in der Lage, nur "" Element zu bekommen. Aber ich möchte "Eintrag" -Element bekommen, wo Exit-Status! = Bis 0 ist. –
Durch die Verwendung von oben XPath, kann ich nur ** ** Element erhalten. Aber ich möchte "Eintrag" -Element bekommen, wo ** Exit-Status! = Auf 0 **. –
In diesem Fall wird eine kleine Änderung am obigen XPath vorgenommen: '/ d: feed/d: Eintrag [sop: status/@ rc! = '0']' – har07