QuickBooks 客户查询响应

QuickBooks Customer query response

我不是 XML 专家,这是我要解决的问题。当我 运行 查询客户列表时,我得到了这个 XML 响应表单 QuickBooks,正如您在节点 <CustomerRet> 中看到的那样,子节点并不总是相同的,我已经尝试过使用 xmlDocument 从子节点 <FullName><CreditLimit> 获取值,当我尝试读取节点 <CreditLimit> 时出现错误,因为并非在所有 <CustomerRet> 实例上.

有没有办法知道节点何时不存在并继续下一个客户?或者有没有办法只查询客户名称和信用额度这两个字段的快速书籍?

这是请求:

  Private Shared Function GenerateXmlRequest_CustomerQuery()

    Dim sbRequest As StringBuilder = New StringBuilder()

    sbRequest.Append("<?xml version=""1.0"" encoding=""utf-8"" ?>")
    sbRequest.Append("<?qbxml version=""" & ClsCommon.GetQBVersion + """?>")
    sbRequest.Append("<QBXML>")
    sbRequest.Append("<QBXMLMsgsRq onError=""continueOnError"">")
    sbRequest.Append("<CustomerQueryRq requestID = ""0"">")
    sbRequest.Append("<ActiveStatus >ActiveOnly</ActiveStatus>")
    sbRequest.Append("</CustomerQueryRq>")
    sbRequest.Append("</QBXMLMsgsRq>")
    sbRequest.Append("</QBXML>")
    Return sbRequest.ToString()
End Function

这是回复:

<?xml version="1.0" ?>
<QBXML>
   <QBXMLMsgsRs>
      <CustomerQueryRs requestID="0" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
         <CustomerRet>
            <ListID>800002FB-1556242302</ListID>
            <TimeCreated>2019-04-25T20:31:42-06:00</TimeCreated>
            <TimeModified>2019-06-24T15:13:21-06:00</TimeModified>
            <EditSequence>1556242302</EditSequence>
            <Name>Company A</Name>
            <FullName>Company A</FullName>
            <IsActive>true</IsActive>
            <Sublevel>0</Sublevel>
            <Balance>1245.00</Balance>
            <TotalBalance>1245.00</TotalBalance>
            <JobStatus>None</JobStatus>
            <PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
         </CustomerRet>
         <CustomerRet>
            <ListID>800002F4-1554669899</ListID>
            <TimeCreated>2019-04-07T15:44:59-06:00</TimeCreated>
            <TimeModified>2019-09-16T12:15:42-06:00</TimeModified>
            <EditSequence>1568654142</EditSequence>
            <Name>Company B</Name>
            <FullName>Company B</FullName>
            <IsActive>true</IsActive>
            <Sublevel>0</Sublevel>
            <CompanyName>Company B</CompanyName>
            <BillAddress>
               <Addr1>Company B</Addr1>
            </BillAddress>
            <BillAddressBlock>
               <Addr1>Company B</Addr1>
            </BillAddressBlock>
            <Balance>0.00</Balance>
            <TotalBalance>0.00</TotalBalance>
            <SalesTaxCodeRef>
               <ListID>80000002-1544571801</ListID>
               <FullName>Company B</FullName>
            </SalesTaxCodeRef>
            <CreditLimit>8000.00</CreditLimit>
            <JobStatus>None</JobStatus>
            <PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
         </CustomerRet>
         <CustomerRet>
            <ListID>800002F6-1555095868</ListID>
            <TimeCreated>2019-04-12T14:04:28-06:00</TimeCreated>
            <TimeModified>2019-04-12T14:04:28-06:00</TimeModified>
            <EditSequence>1555095868</EditSequence>
            <Name>Company C</Name>
            <FullName>Company C</FullName>
            <IsActive>true</IsActive>
            <Sublevel>0</Sublevel>
            <Balance>0.00</Balance>
            <TotalBalance>0.00</TotalBalance>
            <JobStatus>None</JobStatus>
            <PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
         </CustomerRet>
         <CustomerRet>
            <ListID>800002F7-1555096260</ListID>
            <TimeCreated>2019-04-12T14:11:00-06:00</TimeCreated>
            <TimeModified>2019-09-16T12:15:30-06:00</TimeModified>
            <EditSequence>1568654130</EditSequence>
            <Name>Company D</Name>
            <FullName>Company D</FullName>
            <IsActive>true</IsActive>
            <ParentRef>
               <ListID>800002F6-1555095868</ListID>
               <FullName>Company D</FullName>
            </ParentRef>
            <Sublevel>1</Sublevel>
            <Balance>0.00</Balance>
            <TotalBalance>0.00</TotalBalance>
            <CreditLimit>2000.00</CreditLimit>
            <JobStatus>None</JobStatus>
            <PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
         </CustomerRet>
      </CustomerQueryRs>
   </QBXMLMsgsRs>
</QBXML>

使用Xml序列化。空项将为 null

Imports System.Xml
Imports System.Xml.Serialization
Module Module1
    Const FILENAME = "c:\temp\test.xml"
    Sub Main()
        Dim reader As XmlReader = XmlReader.Create(FILENAME)

        Dim serializer As New XmlSerializer(GetType(QBXML))

        Dim qbxml As QBXML = serializer.Deserialize(reader)
    End Sub
End Module

Public Class QBXML
    <XmlArray("QBXMLMsgsRs")>
    <XmlArrayItem("CustomerQueryRs")>
    Public CustomerQueryRs As List(Of CustomerQueryRs)
End Class
Public Class CustomerQueryRs
    <XmlAttribute()>
    Public requestID As Integer
    <XmlAttribute()>
    Public statusCode As Integer
    <XmlAttribute("statusSeverity")>
    Public statusSeverity As String
    <XmlAttribute("statusMessage")>
    Public statusMessage As String

    <XmlElement()>
    Public CustomerRet As List(Of CustomerRet)

End Class
Public Class CustomerRet
    Public ListID As String
    Public TimeCreated As DateTime
    Public TimeModified As DateTime
    Public EditSequence As String
    Public Name As String
    Public FullName As String
    Public IsActive As Boolean
    Public Sublevel As Integer
    Public Balance As Decimal
    Public TotalBalance As Decimal
    Public JobStatus As String
    Public PreferredDeliveryMethod As String
    Public CompanyName As String
    Public CreditLimit As Decimal

    <XmlElement("BillAddress")>
    Public BillAddress As List(Of BillAddress)

    <XmlElement("BillAddressBlock")>
    Public BillAddressBlock As List(Of BillAddress)

    Public SalesTaxCodeRef As CodeRef
    Public ParentRef As CodeRef
End Class
Public Class BillAddress
    Public Addr1 As String
End Class
Public Class CodeRef
    Public ListID As String
    Public FullName As String
End Class