是否可以在VBScript中创建.NET数据表?

时间:2015-05-13 11:29:48

标签: .net vbscript datatable

我有一个返回Datatable的rest API,它包含了它的架构信息。这是一个例子:

<DataSet>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="qryVentListMapping">
    <xs:element name="qryVentListMapping" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="qryVentListMapping" msdata:CaseSensitive="False" msdata:Locale="en-US">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="VentMapId" type="xs:int" minOccurs="0" />
                <xs:element name="VentID" type="xs:string" minOccurs="0" />
                <xs:element name="PatientID" type="xs:int" minOccurs="0" />
                <xs:element name="RoomID" type="xs:string" minOccurs="0" />
                <xs:element name="Unit" type="xs:int" minOccurs="0" />
                <xs:element name="DeviceCategory" type="xs:string" minOccurs="0" />
                <xs:element name="VentType" type="xs:string" minOccurs="0" />
                <xs:element name="VentModel" type="xs:string" minOccurs="0" />
                <xs:element name="IsActive" type="xs:boolean" minOccurs="0" />
                <xs:element name="RoomSeq" type="xs:int" minOccurs="0" />
                <xs:element name="DispOrder" type="xs:double" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <qryVentListMapping>
      <qryVentListMapping diffgr:id="qryVentListMapping1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
        <VentMapId />
        <VentID />
        <PatientID />
        <RoomID />
        <Unit>1</Unit>
        <DeviceCategory />
        <VentType />
        <VentModel />
        <IsActive>true</IsActive>
        <RoomSeq />
        <DispOrder />
      </qryVentListMapping>
    </qryVentListMapping>
  </diffgr:diffgram>
</DataSet>

现在我试过这个:

Set dt = CreateObject("System.Data.DataTable")
 dt.ReadXml(objHttp.ResponseText)

但它给了我这个错误:

  

ActiveX组件无法创建对象 - Microsoft VBScript运行时   错误

有没有简单的方法可以将其反序列化为对象中可用的东西,而无需将其加载到XML文档中并通过它解析(我确实有效)?返回的XML有时会有数千行,并且每隔几秒就会调用它所在的函数。这导致高CPU负载。我需要一种更优雅的方式来处理大量数据。

编辑:这是我现在使用的工作功能。我将所有内容加载到Recordset中并用作表的替代。

Function GetRecordSet(PARAMS, Qry)

    Dim objXML, rs, child, node, qryNode
    Dim URL
    URL = APPLICATION("UIDS_URL") & PARAMS
    Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.setProperty "ServerHTTPRequest", True
    objXML.async =  False
    objXML.Load URL
    Err.number = objXML.parseError.errorCode 
    objXML.setProperty "SelectionLanguage", "XPath"

    dim objNodeList : Set objNodeList = objXML.selectNodes( "//"&Qry ) 

    Set rs = CreateObject("ADODB.Recordset")
    rs.CursorType = 1 ' adOpenKeyset
        rs.LockType = 4 ' adLockBatchOptimistic
        rs.CursorLocation = 2 'adUseClient

    If 0 <> objNodeList.length Then 


        set qryNode = objNodeList(0)

        Set node = objXML.selectSingleNode("//"&Qry)
        For Each child in node.ChildNodes            
            rs.Fields.Append child.NodeName, 8, 10, 4             
        Next   

        rs.open   

        For Each node in objNodeList
            rs.AddNew          
            For Each child in node.ChildNodes            
                rs.Fields(child.NodeName).Value = child.Text  

            Next
            rs.Update   
        Next  
        Set rs.ActiveConnection = Nothing
        rs.MoveFirst    

    end if        

   Set GetRecordSet = rs   

End Function

该功能的使用示例:

Set rs = GetRecordSet ("CQryVentDataDetail?VentId="&VentId&"&InputValue="&InputValue, "qryVentDataDetail")

0 个答案:

没有答案