I have an app that writes to XML. If a text box is filled, then I write that value to the XML doc.

writer.WriteStartElement("VEHICLE_LICENSE_NUMBER") '10-28
            writer.WriteString(frmCitation.txtPlate.Text.ToString)
            writer.WriteEndElement()

If TEST123 is the value in the text box, this is the result.

<VEHICLE_LICENSE_NUMBER>TEST123</VEHICLE_LICENSE_NUMBER>

Question is, if that value in the textbox is empty, and not filled in, how do I not even have that line appear in the XML? I'd like it to disappear unless there's a value.

Does anyone have any ideas?

Recommended Answers

All 2 Replies

See if this helps.

With frmCitation.txtPlate
            If Not .Text = "" Then '// check if TextBox has text.
                writer.WriteStartElement("VEHICLE_LICENSE_NUMBER") '10-28
                writer.WriteString(.Text.ToString)
                writer.WriteEndElement()
            End If
        End With
commented: Thanks codeorder +1

Yup, that did it, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.