Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2006, 10:18 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript and XMLDOM

Hi

I am new to Java script and XMLDOM. I have an XML file on my local sever and I have to send it to a different company using HTTP post. They use XMLHTTP and XMLDOM to retrieve it.

I am a java programmer and I am trying to use Java script and XMLDOM and XMLHTTP to send the file. I know I can use XMLDOM and load the xml file. But I am not sure how to access the file on the local system and save it in XMLDOM.

I am struggling with this problem from the last three days and I really need help…

Can anyone help me with this??????

Thanks




 
Old June 21st, 2006, 11:07 AM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the script I am using. But this is not recognizing the note.xml file in my C drive? Can any one help me with this?

Thanks

<script type="text/javascript">
            var xmlDoc
            function loadXML()
            {
                //load xml file
                // code for IE
                if (window.ActiveXObject)
                {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async=false;
                xmlDoc.load("note.xml");
                getmessage()
                }
                // code for Mozilla, etc.
                else if (document.implementation &&
                document.implementation.createDocument)
                {
                xmlDoc= document.implementation.createDocument("","",null) ;
                xmlDoc.load("note.xml");
                xmlDoc.onload=getmessage
                }
                else
                {
                alert('Your browser cannot handle this script');
                }
            }
</script>

 
Old June 22nd, 2006, 02:53 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

To send the document you will need the XmlHttpRequest, either the Microsoft ActiveX version or the built-in one in Gecko based browsers, Netscape, FireFox etc.
Once you have an instance you call the open method specifying the method, URL and whether to wait for return or carry on processing, you then send the data:
Code:
HttpReq.open("POST", <url to server here>, true); //blocks until server acknowledges or timeout occurs.
HttpReq.send(xmlDoc);
There are plenty of examples in the Microsoft XML sdk and a google search of XmlHttpRequest should show you some cross browser techniques to retrieve the intial XmlHttpRequest object.

--

Joe (Microsoft MVP - XML)
 
Old June 26th, 2006, 02:17 PM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. I made it. But I have an issue again

I have to write a code that runs on the server that posts an XML file to the given URL using XMLHttpRequest Object.

I know that I can use XMLHttpRequest Object on the client side in JavaScript to do this. But is there anyway where I can use XMLHttpRequest object on the server side which can be run as a stand alone application

Can any one give me any idea on this?

Thank You

 
Old June 27th, 2006, 02:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Yes you can, but normally on a server you'd want to use the Msxml2.ServerXmlHttp.4.0 class rather than Msxml2.XmlHttp.4.0. It's quite common to use this as normal security forbids the client retrieving data from a site other than the one whence the page originated. The class can be used to fetch information from a remote server which is then passed to the client.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Pogramming the XmlDOM in C# sencee C# 5 March 10th, 2006 11:09 AM
XMLDOM to load from URL?? lian_a Classic ASP XML 0 January 19th, 2005 10:15 PM
XMLDOM problem braindog_43 Javascript How-To 2 January 16th, 2005 01:54 PM
XMLDOM problem braindog_43 XML 2 January 16th, 2005 01:38 PM
Javascript and using the XMLDOM to modify xml TheNinthPlayer Javascript 1 January 5th, 2005 05:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.