Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building and XML Document

Status
Not open for further replies.

dtqbterror

Programmer
May 17, 2001
87
US
Just wanted to get peoples options on how best to create a XML Document within a VB6 Application.

I have been tasked with taking a VB6 application and making it communicate with a .NET web service. I have been able using the SOAP Toolkit to get the communications working w/attachments but, I am trying to figure out the best way to create the XML Document that is being consumed by the Service.

The structure of the document is static and the only thing that will change is the data contained within. I have thought about defining the structure of the document in a database table and then building it on the fly or just saving the structure as a txt file and just using the replace function to insert the data into it. What is every ones opinion regarding the best way to do this.

Thanks for any input.
 
I don't know about a "best" way, but I used Microsoft's XML SDK to write an application which creates XML documents in a specific format. It took a little while to get my head around first the XML concepts, and then Microsoft's objects and methods, but it was worth it (for me).

You could check out


as a starting point.

Hope this helps

Regards

Daren


Must think of a witty signature
 
Any chance of non-English text being inside the XML document?

If so, you'll need to use the MSXML 4.0 DOM parser methods to create your document:
Code:
Dim MyDoc as New MSXML2.XmlDocument40
Dim MyRoot as MSXML2.IXMLDOMElement
Dim MyElem as MSXML2.IXMLDOMElement
MyRoot = MyDoc.CreateElement("Person")
MyDoc.documentElement.appendChild(MyRoot)
MyElem = MyDoc.CreateElement("FirstName")
MyElem.Text = sFName
MyRoot.appendChild(MyElem)
MyElem = MyDoc.CreateElement("Age")
MyElem.Text = cstr(lAge)
MyRoot.appendChild(MyElem)
Otherwise, it's not totally safe, but you could do string concatenation:
Code:
Dim sXML As String
Dim MyDoc As New MSXML2.DOMDocument40
sXML = ""
sXML = sXML & &quot;<?xml version=&quot;&quot;1.0&quot;&quot;>&quot;
sXML = sXML & &quot;<Person>&quot;
sXML = sXML & &quot;<FirstName>&quot; & sFName & &quot;</FirstName>&quot;
sXML = sXML & &quot;<Age>&quot; & cstr(lAge) & &quot;</Age>&quot;
sXML = sXML & &quot;</Person>&quot;
MyDoc.LoadXML(sXML)
IMPORTANT THINGS TO NOTE:
1) XML doesn't need/use line separators (vbCRLF, etc) or tab characters (vbTab) in order to make it &quot;pretty&quot;. That stuff just bulks up your file and encourages people to read the files as if they were flat-files.
2) String concatenation will get you in trouble if someone slips you a non-ANSI character (VB6 doesn't use UTF-16 Unicode throughout -- just in some places).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top