我遇到了如何通過搜索xml文檔來獲取特定值的問題。這是我第一次使用XML,我已經試過我搜索通過對計算器有以下兩個是什麼,我認爲我是最接近的解決方案與技術的所有方式:雖然在VB.NET中搜索XML
「#1
Dim doc As New XmlDocument()
doc.Load(profilePath)
Dim nodelist As XmlNodeList = doc.SelectNodes("serverconfig/collectorconfig")
For Each node As XmlElement In nodelist
MessageBox.Show(node("clientsslport").InnerText)
Next
「#2:
Dim aProfile As XmlDocument = New XmlDocument
Dim aProfileNodes As XmlNodeList
Dim aProfileNode As XmlNode
aProfile.Load(profilePath)
aProfileNodes = aProfile.SelectNodes("/clientsslport")
For Each aProfileNode In aProfileNodes
frmDebug.lstDebug.Items.Add(aProfileNode.Attributes.GetNamedItem("clientsslport").Value.ToString)
GLOBALDTSERVERS(profileNum).serverFatClientPort = aProfileNode.Attributes.GetNamedItem("clientsslport").Value.ToString
Next
我們的目標是在一個XML文檔來點功能,從XML得到的值,然後加載這些值轉換爲對象的我已經創建。下面是我已經編輯了下來隱私和長度的示例XML文件:從「clientsslport」內/設置/收集者「的PostgreSQL
<dynatrace version="6.2.4.1057">
<serverconfig memento.version="6.2.4.1057">
<collectorconfig usetunnel="false" useproxy="false" authstring="" serverport="6698" groupname="" communicationport="8041" proxyport="8080" embedded="true" compress="true" communicationssl="true" useproxyauthentication="false" proxyhost="" proxyusername="" usepreemtiveproxyauth="true" name="Embedded dynaTrace Collector" watchdogtimeout="10" selfmoncollector="false" serveraddress="localhost" tunnel="http://localhost:8033/tunnel">
<agentlistenaddressconfig>
<listenaddress agentport="9998" agentaddress="" />
</agentlistenaddressconfig>
<loggingconfig append="true" correlationmaxbytes="31457280" console="INFO" level="INFO" maxfiles="5" correlationmaxfiles="2" path="../log/collector/dynaTrace Collector" html="false" maxbytes="10485760" />
<buffers agentbuffersize="32768" />
<protocoldumps maxnumberdumps="100" />
</collectorconfig>
<directories>
<storedsessions path="sessions/stored" />
<temp path="temp" />
<reports path="reports" />
</directories>
<settings>
<collector requirecompression="false" collectoraddress="" collectorport="5001" collectorssladdress="" collectorsslport="5443" allowcollectorconnections="true" collectorauthstring="" requiressl="false" />
<client clientssladdress="" clientport="2020" clientsslport="8443" clientaddress="" requiressl="true" />
<frontend frontendsslport="2031" frontendaddress="localhost" frontendrequiressl="true" frontendport="2030" />
<server tunnelenabled="true" optimizeforthroughput="true" lastvalidedition="DYNATRACE_PRODUCTION" upperdeletiontriggerlimit="153600" collectortunnelenabled="true" continuoussessionrecording="true" lowerdeletiontriggerlimit="5120" collectortunneladdress="" fqdn="<IPADDRESS>" tunneladdress="" id="-1025570809" tunnelport="8023" jmxexportmanagement="false" jmxexportmonitoring="false" autodashboardsupport="true" jmxport="1099" runtimerevision="2" name="<IPADDRESS>" watchdogtimeout="10" collectortunnelport="6608" selfmonitoringenabled="true" agentbasedselfmonitoringenabled="true" hascollector="false" />
<purepath maxnodes="10000" />
<buffers pathwriter="524288" pathreader="1048576" measurementwriter="32768">
<recentlystoredpaths maxsize="250000" maxage="300000" />
</buffers>
<oopanalyzer port="7788" address="" logpath="../log/analysisserver" />
<profilebackups maxbackupfiles="10" />
</settings>
<loggingconfig append="true" correlationmaxbytes="31457280" console="INFO" level="INFO" maxfiles="5" correlationmaxfiles="2" path="../log/server" html="false" maxbytes="10485760" />
<http externalhttpsport="-1" httpport="8080" externalhostname="" webservicesenabled="true" httpsport="8021" webserveraddress="" externalhttpport="-1" webserverenabled="true" webserveraddressssl="" requiressl="false" />
<webstart tunnelenabled="false" proxyauthusername="" proxyautodetectionenabled="false" proxyport="-1" tunnelssl="false" proxyenabled="false" tunneladdress="<IPADDRESS>" tunnelport="8023" anonymouswebstartenabled="true" validationtimestamp="0" webstartenabled="true" proxyaddress="" proxyauthenabled="false" />
<loggingconfig append="true" correlationmaxbytes="31457280" console="WARNING" level="INFO" maxfiles="5" correlationmaxfiles="2" path="../log" html="false" maxbytes="10485760" />
<plugintypeconfig loglevel="INFO" sourcebundlename="com.dynatrace.diagnostics.plugin.SnmpMonitor" bundleversion="6.2.0.1201" name="SNMP Monitor Plugin" active="true" key=
<webui webuihttpsport="9911" webuienabled="true" />
</serverconfig>
<environmentdescriptor memento.version="6.2.4.1057">
<os arch="amd64" name="Linux" version="2.6.32-504.8.1.el6.x86_64" />
<vm vendor="Oracle Corporation" name="Java HotSpot(TM) 64-Bit Server VM" version="24.80-b11" />
</environmentdescriptor>
<repositoryconfig memento.version="6.2.4.1057" lowduration="-1" highduration="1209600000" deletefromhigh="true" midduration="5184000000" querytimeout="7200">
<repository>
<database name="dynatrace62" dbms="PostgreSQL" />
<credential user="<USER>" />
<connection port="5432" usessl="false" host="<IP>" ignorewarnnonproduction="true" useurl="false" connectonstartup="true" embededdatapath="repository" url="<IP>" autopurge_measures="true" />
</repository>
</repositoryconfig>
</dynatrace>
什麼,我希望做的是得到「8443」的價值觀「from」dbms「inside/repositoryconfig。我從整個文檔中加載了更多的值,但是一旦我瞭解瞭如何獲得它,我應該能夠重現它。
在此先感謝您的幫助或見解!
如果你將數據放入對象可以付費使用反序列化,而不是兩種方法har07。有很多方法可以解析xml文檔,使用的方法將取決於您需要從xml中提取的數據量以及xml文件的大小。非常大的文件,你應該使用XMLReader這是另一種類似於har07響應的方法。 – jdweng