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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB6 to create xml file to be uploaded

Status
Not open for further replies.

Leonard

Programmer
Jan 26, 1999
10
US
I have the need, using VB6 to create an XML file that looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<createCustomerProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>YourUserLogin</name>
<transactionKey>YourTranKey</transactionKey>
</merchantAuthentication>
<profile>
<merchantCustomerId>custId123</merchantCustomerId>
<description>some description</description>
<email>mark@example.com</email>
</profile>
</createCustomerProfileRequest>

Can someone please give me some direction and possibly sample code.

The file will be uploaded to a remote server.

Thank you
Leonard


 
Hi JoeAtWork:

Thank you for getting back to me.

The thread from 8 years ago, is not the same.

Best regards

Leonard
 
How is it essentially different? In both cases you are creating a text file. Instead of creating a file called "output.csv" you will create a file called "output.xml".
 
I'm thinking that the xml v?.? references are what the OP needs to read up on instead of using the open/print/close methods of VB...



Good Luck

 
I have the need, using VB6 to create an XML file that looks like the following:

If that's not what the OP really wants he will need to be more specific.
 
Thank you everyone for getting back to me.
I finally figured it out by using:

Dim Fs As Scripting.FileSystemObject
Dim txt As Scripting.TextStream

The code such as :
txt.WriteLine "<?xml version=""1.0"" encoding=""utf-8""?>"
txt.WriteLine "<createCustomerProfileRequest xmlns=" + StrTest1 + ">"

Works fine.
Thanks again
 
Well so much for what I know... :), however Leonard, when concatinating strings you should always use the ampersand (&) symbol as you are not adding (+) strings together in a mathmatical operation...



Good Luck

 
It still isn't strictly correct.

For one thing UTF-8 encoded XML normally uses a LF as a line delimiter. Part of this is just Unixness, part to save space. It isn't critical though.

More importantly in the procesing instruction you claim you're writing it as UTF-8. The FSO can't write UTF-8, you only get a choice between "Unicode" (UTF-16LE) and ANSI. If you are careful not to ever use any characters outside the printable ASCII subset this should work fine though.


However this isn't what I'd call production quality code. It makes many assumptions about its environment and that of anyone consuming the XML.

Using an ADODB.Stream object is one way to convert and write the text. Another would be WideCharToMultiByte API calls with binary file writes.
 
Can I point out that using the FileSystemObject is just an alternative way to accomplish the same thing as Output and Print?
 
Not strictly true though. Using Print you can't write a Unicode file, only ANSI. Most of the time this is good enough though, and in the case at hand he is probably trying to pass ANSI off as UTF-8 anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top