0

嗨,我有一个下面提到的 xml,它是来自数据库的字符串值。我想解析 xml 字符串并且不想保存那些有空的空间,即这个语句意味着它存储了空的空间。我需要在 if 条件下查找此语句,如果为空则不保存。请让我知道该怎么做。下面是xml之后的vb.net代码

<DocumentElement>
  <TBLCustomizedCodes>
    <tblRowkey>-1</tblRowkey>
    <TBLRowCustomizedCodes>test</TBLRowCustomizedCodes>
    <TBLRowCompliance>N/A</TBLRowCompliance>
  </TBLCustomizedCodes>
  <TBLCustomizedCodes>
    <tblRowkey>-2</tblRowkey>
    <TBLRowCustomizedCodes xml:space="preserve">      </TBLRowCustomizedCodes>
    <TBLRowCompliance xml:space="preserve">      </TBLRowCompliance>
  </TBLCustomizedCodes>
  <TBLCustomizedCodes>
    <tblRowkey>-3</tblRowkey>
    <TBLRowCustomizedCodes xml:space="preserve">      </TBLRowCustomizedCodes>
    <TBLRowCompliance xml:space="preserve">      </TBLRowCompliance>
  </TBLCustomizedCodes>
</DocumentElement>
Dim ds As DataSet = New DataSet("DocumentElement")
        ds.Tables.Add(tempdataTable)

        Dim valueXML As String = ds.GetXml().ToString().Trim()
        SaveInspectionSupplementalLineItem(valueXML)
4

2 回答 2

0

您可以String.IsNullOrWhiteSpace(string)在保存之前检查它是否为空

Dim ds As DataSet = New DataSet("DocumentElement")
ds.Tables.Add(tempdataTable)

Dim valueXML As String = ds.GetXml().ToString().Trim()
If Not String.IsNullOrWhiteSpace(valueXML) Then
    SaveInspectionSupplementalLineItem(valueXML)
End If
于 2020-08-24T16:09:58.503 回答
0

也许这会有所帮助

    Dim xe As XElement
    Dim valueXML As String = ds.GetXml() '.ToString() '??? 
    xe = XElement.Parse(valueXML)
    Dim ie As IEnumerable(Of XElement)
    ie = From el In xe.Descendants Where el.Value.Trim = "" Select el
    If ie.Count > 0 Then
        'there WERE Elements with empty space
        Stop 'look at ie.Results
    Else
        'no empties
    End If
于 2020-08-24T19:36:26.963 回答