我的SQL查詢返回一個實際上是XML的列結果。當我點擊記錄集時,它會打開一個results.xml
。使用VBScript將記錄集轉換爲XML
這是輸出XML我抓進result_string
使用
result_string = objRecordSet.Fields(colname).Value
<TEST_SUITE SUITE_ID="122675741" PART_NUMBER="MTSTE-26248-00" REVISION="A" SUITE_TYPE="PRODUCTION" SUITE_NAME="HOT-LOW" SUITE_STOP_ON_FAIL="TRUE" TARGET_DURATION="0" SEQUENCE="1" UPDATED="2016-12-15T00:21:46.510">
<SUITE_DESCRIPTION>"HOT-LOW"</SUITE_DESCRIPTION>
<TESTS>
<TEST TEST_ID="122663528" TEST_NAME="Set Suite Environment Variables" PART_NUMBER="MTTST-65899-00" REVISION="A" MODULE="TEST Set Environment Variables.vi" MODULE_LIBRARY="BIG-IP_TESTS" TEST_STOP_ON_FAIL="TRUE" TEST_TYPE="BEGIN_SESSION">
<PARAMETERS>
<PARAMETER PARAMETER_ID="122663469" PARAMETER_NAME="TOS" PARAMETER_VALUE="build_2.0.1.1647.0_centos6_x86_64" />
<PARAMETER PARAMETER_ID="82137" PARAMETER_NAME="chain" PARAMETER_VALUE="TRUE" />
</PARAMETERS>
<MEASUREMENTS>
<MEASUREMENT MEASUREMENT_ID="70784" MEASUREMENT_NAME="TOS" UNITS="" UPPER_LIMIT="" LOWER_LIMIT="" COMPARISON="LOG" INPUT_SCALE_FACTOR="" OUTPUT_SCALE_FACTOR="" />
<MEASUREMENT MEASUREMENT_ID="81537" MEASUREMENT_NAME="chain" UNITS="" UPPER_LIMIT="" LOWER_LIMIT="" COMPARISON="LOG" INPUT_SCALE_FACTOR="" OUTPUT_SCALE_FACTOR="" />
</MEASUREMENTS>
</TEST>
</TESTS>
</TEST_SUITE>
從這個
我需要一個爲test_id。我如何存儲XML到這個result_string
並獲得Test_ID。或者有沒有簡單的方法來獲得Test_ID?
我做了這樣的事情,但不知道這是否正確,並且我在線路objCommand.Execute ,, adExecuteStream
上收到錯誤。
Dim strm
Set strm = CreateObject("ADODB.Stream")
strm.Open
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = script_testID
objCommand.Properties("Output Stream")= strm
objCommand.Properties("Output Encoding") = "UTF-8"
objCommand.Properties("XML Root") = "Root" 'this can be anything you want
objCommand.CommandType = 4
objCommand.Execute ,, adExecuteStream
strm.Position = 0
text = strm.ReadText
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "false"
xmlDoc.LoadXML(strm.ReadText)
strm.Close : Set strm = Nothing
Set objCommand = Nothing
其實問題是關於XML解析,並且不與SQL和相關的記錄,所以SQL標籤是無關緊要的。 – omegastripes
Try'test_id = Split(Split(result_string,「TEST_ID =」「」,2)(1),「」「」,2)(0)' – omegastripes
哇,謝謝@omegastripes。非常感謝您的及時幫助。 – user2329418