How to Use a VB6 Application Code to Remove XML Tags From a String
Visual Basic 6 has a function called "Replace" that removes parts of a string. You can use the "Replace" function to remove XML tags from a string. This is useful when you pass XML back and forth with a user. XML is a type of encoding that offers standard tags. It is typically used when you are passing data from a database to an application. Stripping the XML tags from a string lets you show the data without the XML tags.
Instructions
-
-
1
Click the Windows "Start" button and select "All Programs." Click "Microsoft Visual Basic," then click "Visual Basic Studio" to open your software.
-
2
Click "File > Open" to open your Visual Basic project. The project has the "SLN" extension which stands for "solution." After you open the file, you are shown your code window, which is where you type in the code to remove the XML tags.
-
-
3
Create your XML string. For example, the following creates an XML string with a customer name:
Dim myCust As String
myCust = "<customer>Joe Smith</customer>"
-
4
Remove the XML tags from the string. You use the "Replace" function to remove these tags. You must remove the first tag, then remove the second closing tag. The following shows you how to remove the tags:
myCust = Replace(myCust, "<customer>", "")
myCust = Replace(myCust, "</customer>", "")
In this example, the tags are replaced with a zero-length string, so only the customer's name is left in the "myCust" variable.
-
5
Click the "Save" button in your Visual Basic toolbar. Click "Run" to execute the code and view your new changes.
-
1