Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Saving XML document

Posted on 2004-09-22
5
Medium Priority
?
644 Views
Last Modified: 2012-06-27
I am new to Web development and am trying to create an HTML page that allows users to read from a XML document, edit the data, then save the changes to the document. Here is the code I'm using:

<XML id=xmldso></XML>

<SCRIPT LANGUAGE=vbscript>
      xmldso.async = False
      xmldso.load "http://www.<server>.com/<doc>.xml"
      
      Function SaveRecord()
            xmldso.save xmldso.XMLDocument
      End Function
</SCRIPT>

<BODY>
      <TABLE DATASRC='#xmldso' BORDER CELLPADDING=3>
            <THEAD>
                  <TH>ID</TH>
                  <TH>NAME</TH>
            </THEAD>
            
            <TR>
                  <TD><INPUT TYPE=TEXT DATAFLD="ID"></TD>
                  <TD><INPUT TYPE=TEXT DATAFLD="Name"></TD>
            </TR>
      </TABLE>
      
      <INPUT TYPE=BUTTON VALUE="Save" onclick="SaveRecord">
</BODY>

I get no error message, but the changes are not saved. I am trying to do this without using ASP if at all possible. Anyone have any suggestions or see obvious mistakes I'm making?

TIA,

Jeff
0
Comment
Question by:Jeff Tennessen
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 12129197
This bit:

    Function SaveRecord()
          xmldso.save xmldso.XMLDocument
     End Function


saves the XML document to itself...though I'm surpised it doesn't error out.  What you need is:

    Function SaveRecord()
          xmldso.XMLDocument.save "foo.xml"
     End Function


**HOWEVER**

this won't be possible in a web page without modifying the client security settings.  Imagine what would happen if any website you visited could save arbitrary data to your hard drive...

I use HTA (html applications) to do this, but they typically aren't served from a web server.  They work like a compiled executable, except they're not compiled.  If you try to serve one from a web site, it will throw a warning dialog to the user.  If it opens from the local filesystem, then no problems.

If you want to save the XML to the server, then this is easily accomplished.  But If you want the document to be saved to the local user's file system, it's much harder and in general there are two approaches.  One is to write a java applet that is installed to the user's system, and the other is to write an ActiveX control that does the same thing.  But in either case, the code needs to be signed, and in most cases the first time a user navigates to the page they'll get a dialog asking them if they want to install this-and-such program.

This is essentially how a content management system like Interwoven TeamSite works.  Content authors interact with the CMS, and there is a need to both upload and save stuff locally.  

I have a tool that I use to run transformations on a machine that doesn't have XML Spy.  I have several versions, but the one that saves to the local filesystem is an HTA.  There is a lot of good code in there for you to take a look at.  You can find it at:

http://rdcpro.com/Members/rdcpro/tools/

The one you're interested in is called transformToolSave.zip

Also, as far as data islands go, unless you have a compelling reason to use them, I'd avoid them.  They may be convenient, but they are not flexible, there's a lot you can't do with them, and they use the the old parser API, so if you ever do an XSLT with them, or want to do anything else, you need to load them into a DomDocument.3.0 or DomDocument.4.0 object anyway.  

Study the code in those transform tools...it might help you out.
 


Regards,
Mike Sharp
0
 
LVL 8

Author Comment

by:Jeff Tennessen
ID: 12129938
Hi Mike,

Thanks for the very detailed reply! Unfortunately, a lot of it was over my head. <g> I tried changing the SaveRecord function as you suggested and now it *is* throwing an error (Permission denied: 'xmldso.XMLDocument.save'), as I guess one would expect from reading the rest of your post. It occurs to me that I may not have explained myself well. Nothing will be saved to the user's local hard drive. Both the html page and the xml data will reside on the server -- if that makes a difference...

I'm going to take a look at the code in the transform tools and will post back after I've seen what I can glean from them.

Much appreciated!

Jeff
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 1000 total points
ID: 12137111
Ah that's good.  Server-side is a piece of cake.  In fact, much of the code in those tools will work with a little modification on the server...But it's going to require some sort of server-side processing language in an application server, whether it be Javascript using ASP, python using Apache, or whatever.

If you're able to restrict users to IE 6 (Or IE 5/5.5 with MSXML 3 installed) you can use the XMLHTTPRequest object to post the XML data to the server.  There needs to be either a posting acceptor, some sort of server-side ASP, or a CGI or something to take the XML, possibly validate it, and then save it to wherever.  A common scenario is saving it to a database...If you have MSDE or SQL Server 2000, you can set up a virtual directory that will do this without any server-side code (meaning without ASP).

You can put the XML in a hidden form field and post it, or you can post the form to the server, and construct the XML there...

Regards,
Mike Sharp

0
 
LVL 8

Author Comment

by:Jeff Tennessen
ID: 12137288
Hi Mike,

That really sounds like an approach worth exploring! Can you recommend any resources to get me started?

Thanks again,

Jeff
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 12138278
Sure thing.  Its all pretty well documented in SQL Books online, but I don't know if the MSDE comes with the help docs.  I know it doesn't come with the client tools, but it's priced right: free.

The best bet is to download Microsoft's SQL XML 3.0 toolkit, and read through the help documentation.  

Here's a PAQ'd question I answered the other day that had a user who wanted to upload data to SQL Server.  The data was in XML form, and this solution transformed the XML into an updategram (these are cool, once you get a handle on all this, check 'em out) and then posted the updategram to the SQL Server.  It ran from a client side javascript that ran under windows scripting host, but you can do the same thing in an HTML page, if you use IE.  Basically you'll use whatever technique you want to create the XML (perhaps with DOM operations, or whatever, in the browser.  Then a "submit" constructs an Updategram that posts to the server.  Here's the link:

http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21133476.html

You can also do this with web services and SOAP.

Regards,
Mike Sharp
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question