Results 1 to 18 of 18

Thread: help with XML

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    help with XML

    hi,

    I have an xml file which may or may not have information in a particular node.
    I am trying to assign the value of this element (which will either be a 1 or nothing) to a variable called strTest.

    This works fine if the element contains a "1" , however if the element is empty i get an automation error (clearly cause you cannot assign an empty node.typedValue to a string.

    Can any1 suggest how i can ckeck to see if the node.typedValue is a "1" and if so to assign it to a string, but if its empty to assign a "0" to the string

    or perhaps using a 1,0 boolean


    For i = 0 To nodes.Length - 1
    strTest (nodes.NextNode.selectSingleNode("REASON").nodeTypedValue)
    Next

    thanks in advance

  2. #2

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    here you go:

    Dim xmlDocIssueNumber As DOMDocument
    Set xmlDocIssueNumber = New DOMDocument
    xmlDocIssueNumber.preserveWhiteSpace = True
    xmlDocIssueNumber.loadXML (cIssueNoXML)
    xmlDocIssueNumber.Save ("C:\Documents and Settings\Simon Pogrebinsky\Desktop\xmlSave\issueNo.xml")
    Set nodes = xmlDocIssueNumber.selectNodes("//NewDataSet/AUTONUMBTABLE/AUTOFLAG")



    For i = 0 To nodes.Length - 1
    If Not (nodes.NextNode.selectSingleNode("AUTOFLAG") Is Nothing) Then strFaultFlag = ((nodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue))

    Next

    MsgBox (strFaultFlag)

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: help with XML

    VB Code:
    1. Dim NextNode As IXMLDOMNode
    2.     Set NextNode = Nodes.NextNode.selectSingleNode("REASON").nodeTypedValue
    3.     If Not (NextNode Is Nothing) Then
    4.         If nodes.NextNode.selectSingleNode("REASON").nodeTypedValue ="1" Then
    5.             strTest = "1"
    6.          Else
    7.              strTest = "0"
    8.         End If
    9.     End If

  5. #5

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    thanks for the help my code is now:

    VB Code:
    1. Dim xmlDocIssueNumber As DOMDocument
    2.     Dim NextNode As IXMLDOMNode
    3.     Set xmlDocIssueNumber = New DOMDocument
    4.     xmlDocIssueNumber.preserveWhiteSpace = True
    5.     xmlDocIssueNumber.loadXML (cIssueNoXML)
    6.     xmlDocIssueNumber.Save ("C:\Documents and Settings\Simon Pogrebinsky\Desktop\xmlSave\issueNo.xml")
    7.     Set nodes = xmlDocIssueNumber.selectNodes("//NewDataSet/AUTONUMBTABLE/AUTOFLAG")
    8.    
    9.     For i = 0 To nodes.Length - 1
    10.         Set NextNode = nodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue
    11.             If Not (NextNode Is Nothing) Then
    12.                 If nodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue = "1" Then
    13.                     strFaultFlag = "1"
    14.                 Else
    15.                     strFaultFlag = "0"
    16.                 End If
    17.             End If
    18.      Next
    19.      MsgBox (strFaultFlag)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    however i still get a runtime error,

    thanks for your help btw

  8. #8

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    sure here you go, this is the XML file where the AUTOFLAG typed value is "1"
    Attached Files Attached Files

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    hmm, its actually an object required error now

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    have you had any ideas on this? sorry to keep asking

  12. #12

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    well, as this is a COm addin for outlook I cannot really debug, however using message boxes it gets to this line:

    VB Code:
    1. Set NextNode = Nodes.NextNode.selectSingleNode("REASON").nodeTypedValue


    and an object required error occours

  14. #14

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    ok this is the actual line:


    Set NextNode = nodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: help with XML

    The NodeList you are creating is already a list of AUTOFLAG nodes so you don't need to go any deeper. That simplifies it a bit. I also changed "nodes" since that's a reerved word.

    VB Code:
    1. Dim xmlDocIssueNumber As DOMDocument
    2.     Dim NextNode As IXMLDOMNode
    3.     Set xmlDocIssueNumber = New DOMDocument
    4.     xmlDocIssueNumber.preserveWhiteSpace = True
    5.     xmlDocIssueNumber.Load "C:\vb examples\xml\test.xml"
    6.     Dim oXMLNodes As IXMLDOMNodeList
    7. '    xmlDocIssueNumber.loadXML (cIssueNoXML)
    8. '    xmlDocIssueNumber.save ("C:\Documents and Settings\Simon Pogrebinsky\Desktop\xmlSave\issueNo.xml")
    9.     Set oXMLNodes = xmlDocIssueNumber.selectNodes("//NewDataSet/AUTONUMBTABLE/AUTOFLAG")
    10. '    Dim i, strFaultFlag
    11. '    For i = 0 To oXMLNodes.length - 1
    12. '        Set NextNode = oXMLNodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue
    13. '            If Not (NextNode Is Nothing) Then
    14. '                If oXMLNodes.NextNode.selectSingleNode("AUTOFLAG").nodeTypedValue = "1" Then
    15. '                    strFaultFlag = "1"
    16. '                Else
    17. '                    strFaultFlag = "0"
    18. '                End If
    19. '            End If
    20. '     Next
    21.  
    22.     Dim i, strFaultFlag
    23.     For i = 0 To oXMLNodes.length - 1
    24.         If oXMLNodes(i).nodeTypedValue = "1" Then
    25.             strFaultFlag = "1"
    26.         Else
    27.             strFaultFlag = "0"
    28.         End If
    29.         MsgBox strFaultFlag
    30.      Next

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: help with XML

    thanks very much - works well

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: help with XML

    You're welcome. Now that we've helped you, you can help us by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button which will let everyone know that you have your answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width