Link to home
Start Free TrialLog in
Avatar of Leithauser
Leithauser

asked on

XML Messaging in VB

I have a VB program that I need to add XML messaging to. Specifically, I need the program to be able to generate an XML file, post it to a Web site, and receive a confirmation reply. Since I need to be able to add this to an existing program ASAP, the ideal answer to this question would be some code that I could add to my program, some control that could be added to a VB program, or at least some DLL that could be distributed freely with the program.
ASKER CERTIFIED SOLUTION
Avatar of anthonywjones66
anthonywjones66

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leithauser
Leithauser

ASKER

Anthony:

    Thanks. This seems to be on the mark, although I am not familiar with this reference and will need time to check it out. A few question:
1) What is "http://MyServer/MyXMLAcceptor.asp"? Is this a file I need to create? What does it do?
2) What is the false?
3) What is strXML? Is that a string containing the name and path of the XML file to be sent?
4) I assume that HttpReq.responseText is a string containing the response, something like "Success" or an error message. Correct?
5) The "more indepth example" seems to be for retrieving an XML file from a server, not posting one. Is that correct? I am not sure whether I will need that or not.
   I also am not sure whether I will need help creating the XML file. I doubt it. After all, an XML file is basically just a text file, so I should easily be able to create one using plain old string manipulation in VB code.
  To clarify my question, I have been requested to add XML and a few other features to a program I already market. I have not yet been given all the specs, so I am not clear on the details. I will post more when I get them. If the problem needs to be extended and you continue to provide help, I could increase the points before awarding them to you. Or, I could post a separate question regarding additional requirements for the modification as the client explains them better. I just wanted to get a jump on this research since once the client gives me the specs, they will probably be in a hurry.
1) Sorry a bit cryptic. This the ASP page on the web server you need to create to accept the XML post.
2) The third parameter of the open method indicate whether the post should be performed asynchronously.   Since you want to wait for a response you don't want an asynchronous post.
3) strXML is the string holding the actual XML you want to post.
4) Yes it will contain whatever response you make from 'MyXMLAcceptor'.  It's probably best to make this XML.  I use <success />.
5) Yes sorry about that not a good example.

You probably don't want to be building XML with strings in VB.  If you're serious about getting the jump on the research give this section of MSDN a good read:-

http://msdn.microsoft.com/library/en-us/xmlsdk/html/DOM_HDI_VB.asp

This is also good:-

http://www.w3schools.com/dom/default.asp

Anthony.
<<1) Sorry a bit cryptic. This the ASP page on the web server you need to create to accept the XML post.>>

    This is confusing. My program will be running on individual computers. The program on each computer will need to do XML messaging with a central server at another location by Internet to update information. Does the ASP page go on the computer running my program, or does it go on the central server? If it goes on the central server, creating this file is not my responsibility. The people requesting the modification are in charge of setting up the central server. Assuming that it does go on the central server, do I just put the URL of the page on the server where you have "http://MyServer/MyXMLAcceptor.asp" in your example?

<<3) strXML is the string holding the actual XML you want to post.>>

   Just to make sure I am absolutely clear here, is strXML the actual XML string, or is it a string like "C:\MyFolder\File.xml" that points to the XML file?

<<4) Yes it will contain whatever response you make from 'MyXMLAcceptor'.  It's probably best to make this XML.>>

      When you say "you make", do you mean the response that the server sends back? I may be a little confused because I will not be handling the server part of this project, so I will not be making the response, just accepting it.


<<You probably don't want to be building XML with strings in VB.>>

    I do not see why not. XML files are just strings of text. I have written programs that generated HTML files, and they are more complicated than most XML files I have seen. Is there a problem I do not know about?

<<  If you're serious about getting the jump on the research give this section of MSDN a good read:->>

    Thanks. Will do.

1)  It goes on the central computer.  If this is not your responsibility then somewhere you and they need to agree an XML format and the URL to which you post that XML.

3) strXML is the actual XML NOT a file path.  

4) Ok then you need to agree what that response is and 'encourage' your partner to respond with XML.

You can build XML with strings as long as you properly escape < and & with &lt; and &amp; and you don't mind re-inventing the wheel. However the XML DOM is designed to do just that and you already have it referenced in your project so you may as well use it.

Anthony.
<<1)  It goes on the central computer.  If this is not your responsibility then somewhere you and they need to agree an XML format and the URL to which you post that XML.>>

     As I understand what they are asking, they already have a central computer set up to receive the information, and are already doing it with other software. They already have an XML format in mind (in fact they send me a description of the format). Based on what you have told me, I assume they have an ASP file set up to receive data on their central server, so all I need to do is point the HttpReq.open "POST" to it. If all this is correct, things will progress nicely once I set up the code you sent me.

    Incidentally, you mentioned Microsoft XML 3.0. Although I did find that reference on my VB 6, my quick research indicates that this needs to be updated. They seem to be on 5.0. Apparently this is necessary to comply with security patches that may block Microsoft XML 3.0. As I understand it, I need to download a patch from Microsoft that will upgrade me to 5.0. I hope it is just a matter of downloading something to my computer that will add XML 5.0 to my VB reference list.

<<3) strXML is the actual XML NOT a file path.>>

    Good.

<<4) Ok then you need to agree what that response is and 'encourage' your partner to respond with XML.>>

    As I understand it, that is what the partner is requiring of me. That is, it was their desire to have me add XML messaging to my program so that my program can interact with their system.

<<You can build XML with strings as long as you properly escape < and & with &lt; and &amp; and you don't mind reinventing the wheel. However the XML DOM is designed to do just that and you already have it referenced in your project so you may as well use it.>>

    Can you explain what you mean by "escape < and & with &lt; and &amp;"? I am not sure I understand your use of the word "escape" there. Basically, the way I see it, I have been given an XML format by my partners, and I need to insert data values in places they have marked by variables. It looks to me like the easiest way to do that is to read the file in as a string, replace the variable names with values using string manipulation, and then store this string in strXML and send it. Then I get the response to confirm it, and my program has done its part.
I have accepted the answer posted by anthonywjones66. I apologize for taking so long to do so. I was more or less waiting for a reply to my final question. However, the information given in the previous replies definitely solved the problem, so I am awarding an Excellent to this answer.
Liethauser,

My apologies for not replying to your final query, I must have missed it in my initial reading.

In text streams such as xml there are often characters that have special significance.  In XML for example the < character begins an element tag name.  So what happens if the text you want to insert contains a < character.  We need to somehow 'escape' this being intepreted as a the begining of a tag name.  This is done by replacing the < character with another sequence of a known format.  XML uses & as an escape character and specifically the sequence &lt; means 'put a < character here'.  Hence any < in your data need to be replaced with the sequence '&lt;' before you include it in the XML.

Of course since & now has a special meaning it needs to be 'escaped'.  Hence any & in you data needs to be replaced with '&amp;'.

Thanks for the points,

Anthony.