XML True/False to Boolean and Back

Posted on 2006-05-28
Last Modified: 2010-05-18
In my application form I have a checkbox we will call cbxSub.
In my XML I have <sub>True</sub>  or it cam be <sub>False</sub>

Two part question:

If I need to read from the XML to the check box how will I do that? I know I could look at the string and say "If True then" or "If false then" but I am pretty sure there is another way.

Then if I have the checkbox and it is changed, how do I store the new value in the XML file?

Question by:sneeri_c
    LVL 52

    Accepted Solution

    Assuming you have your <sub> node in an IXMLDOMNode called "node", then you could try:

        If CBool(node.Text) Then
            cbxSub.Value = vbChecked
        End If
    LVL 6

    Expert Comment

    Just put 2 command buttons and 1 checkbox on a form, and reference Microsoft XML v3.0, then try the following code:

    Option Explicit
    Dim oDoc As New MSXML2.DOMDocument30

    Private Sub Command1_Click()
        Dim currNode As IXMLDOMNode
        oDoc.async = False
        Call oDoc.Load("c:\a.xml")
        For Each currNode In oDoc.childNodes
            Check1.Value = IIf(CBool(currNode.Text), vbChecked, vbUnchecked)
    End Sub

    Private Sub Command2_Click()
        Dim currNode As IXMLDOMNode
        Dim bol As Boolean

        For Each currNode In oDoc.childNodes
            bol = IIf(Check1.Value = vbChecked, True, False)
            currNode.Text = CStr(bol)
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
        Set oDoc = Nothing
    End Sub

    The content of a.xml should be:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now