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

How to save a string to an XML file Client Side? I AM DESPERATE 1

Status
Not open for further replies.

coderGirl

Programmer
Oct 21, 2003
22
0
0
AU
Please i need to know how to get the folowing code or somethng totally differen to work client side

<script language=&quot;javascript&quot;>
function GetXML()
{
var strXML = new String();
strXML = &quot;<?xml version='1.0'?>\n&quot;;
strXML = strXML + &quot;<root>\n&quot;;
strXML = strXML + &quot;<name>\n&quot;;
strXML = strXML + &quot;\t<first>FirstName</first>\n&quot;;
strXML = strXML + &quot;\t<last>LastName</last>\n&quot;;
strXML = strXML + &quot;</name>\n&quot;;
strXML = strXML + &quot;</root>&quot;;
alert(strXML)
var doc = new ActiveXObject(&quot;msxml2.DOMDocument.4.0&quot;);
doc.async = false;
doc.resolveExternals = false;
doc.validateOnParse = false;

//Load an XML doc into the DOM instance.
doc.loadXML(strXML);

//Save the dom to a file.
//result.innerHTML=strXML;
doc.save(&quot;c:\saved.xml&quot;);

alert(&quot;Saved&quot;);
}
 
First try change:

var doc = new ActiveXObject(&quot;msxml2.DOMDocument.4.0&quot;);

to

var doc = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;)

This solve one of your problem in creating XMLDOM object. However, you still have problem in saving the file due to permission issue. Browser client is not allowed to read/write file from/to local system. I don't know if there way get around this.
 
Would you know if it is possible with VB script?

I know this isn't the correct forum but i thought you might know
 
Certainly possible in VBScript or JavaScript. The problem is that the MSXML components will only handle half of the problem for you. You look to have the XML object creation under control, so now we need to look at saving the file.

Due to security restrictions, I wouldn't recommend this course of action for an Internet application, you'd want to be working in either an Intranet, or a very tightly controlled Extranet environment.

The MSXML components, as you will have by now realised, have no native file handling mechanism. For this you'll either need MS Data Access Components or File System Objects. FSO only handles text files, but since that's all we need for XML that's what we'll use.

Code:
// Load the XML into the existing MSXML object
doc.loadXML(strXML);

// Create a File System Object
var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);

// Use the fso to create a new text file
var xmlFile = fso.CreateTextFile(&quot;c:\\myfile.xml&quot;, true);

// Extract the XML DOM to a variable
var xmlDomStr = doc.xml;

// Write the text into the text file
xmlFile.Write(xmlDomStr);

// Close off the text file
xmlFile.Close();

See where that takes you. You may need to do some fiddling with your IE settings to get the objects to automate without needing an OK from the user. Oh, and as if I need to say it, the above code is IE only.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Thanx heaps it worked

Now one last thing would you know hoe i could have a button on the screen which would execcute a JAVA class.

as i have to use java so then read the created XML i know it's not really a good way of doing this but i just need to get basic functionality to show my boss.

cheers
 
Do you have to use Java? Using Java on the client side is a pain. You would either have to wrap up the Java as an applet - in which case getting the browser to provide the applet with access to the local file system will be really painful. Or you can use the Java on the back end through CORBA to the front end which means that your Java Class and server need to be IIOP enabled.

I guess if you created a batch file you could run a stand-alone Java class from a link to the .bat file, but that would require not only knowing that the .bat and .class files were on the client machine, but also where on the client machine they were. And unless you can ensure that each of the client machines has the appropriate JVM installed - more pain.

What is it you need to do with the created XML? Perhaps there is a client side script we can flesh out to do the processing?

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
weLL YOU C I FEEL I HAVEBEEN STUFED ROUND WITH THIS BUT YOU I ALREADY HAVE THE JAVA PROCESSOR OF THE xml DONE AND YOU C I JUST NEED TO SOME HOW HAVE USERS TYPE IN DETAILS, THEN HAVE AN xml FILE CREATE FROM THE DETAILS AND THEN HAVE THE xml DOC SENT TO MY JAVA


iT'S A REALL SILLY BUT I TIHNK I JUST NEED TO GET FUNCTIONALITY MORE THEN ANYTHING

ALTHOUGH THERE HAS BEEN TALK OF ME POSSIBLY CHANGING TO USING SERVELETS ALTHOUGHI HAVE NO IDEA HOW TO USE THEM

WHAT YOU SAY BOUT THEM
 
OK, servlets are good. There's not much too them... Basically a servlet is a little application that runs server-side, as opposed to an applet which runs client side.

Now because a servlet runs on your server, it can do things that an applet could never do on a client machine - like file processing.

A servlet has two 'main' methods - Post and Get, which correspond to the two methods used by HTML forms to submit information. So you could use the IXMLHTTPRequest object to post the XML file you created to your servlet and do all the processing you need.

I think that's probably the best way to go.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
hmm i found this program called jetty not sure if you heard of it.

So can now work withserver side servelets, Would by any chance have some sortof basic sample of a web page which uses a sevelet.

That would be greatly appreciated
 
Web pages, don't use servlets per se, a servlet could be considered a web page though. A servlet is a standalone application that responds to a HTTP request. The most basic servlet is - naturally - &quot;Hello World&quot;. Line by line, here's the anatomy of a hello world servlet:
Code:
  // Imports the Java Packages needed for this servlet
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;

  // Class declaration of the HelloWorldServlet
  public class HelloWorldServlet extends HttpServlet 
  {
    /* 'doGet' is the method that executes when the servlet
       is called via a HTTP GET request.
    */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
      // Set the output type to html
      response.setContentType(&quot;text/html&quot;);

      // get a handle on the output (the browser)
      PrintWriter out = response.getWriter();
 
      // Write some HTML out to the browser
      out.println(&quot;<html><body>Hello, world</body></html>&quot;);

      // Close off the output stream.
      out.close();
    }
  } // All done.

There are plenty of resources around:

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Thankyou i still am unsure of how they run but i will look at these sites thanx heaps for you time
 

Hello All,

After searching several posts, I thought I'd try asking the question here.

I'm trying to build an XML request, transmit the data over the web, and then unpack the XML response sent back using VBA or VB

I have the URL address, a sample(if you can it that) of the XML code with default values.

I need help or a point in the right direction, how to do this in MS Access. The code here looks like I'm on the right track. I'm just not sure how to go about setting it up.

Any help would be greatly appreciated!
Trying to incorporate this in a Phone Orders db, that will retrieve postal rates from USPS. But they offer very little help.

My main question is: Can I do this without a webserver?
From the samples, it looks like all the processing is done on the usps site, then a response is sent back(The postage).

Thanks in advance, for taking the time to help fellow programmers.


AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Hi Carl.

You'd be much better off posing your question in the Access ( forum702 ), VBA ( forum707 ), or VBScript ( forum329 ) forums.

Point them to this thread and request ideas on how best to do it in access.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 

Thanks dwarfthrower,
I already have posted the question in another Access forum, but after reviewing the code posted here, I thought maybe someone would have an idea.

Thanks anyways...


AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top