Toan Nguyen

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromToan Nguyen
ToMe
SubjectsaveXML does not work + why not only document.getElementById
Date9 November 2006 00:35
Hi Mark,
   
  Your howtocreate site is truly useful. Thank you for taking the time to
write your tutorials.
  
  I wanted to read and save an XML file the easiest way and so I used
Microsoft's  proprietary XMLDOM object. The problem is reading and modifying
an XML file (using XMLDOMOb.load('myfile')  + appendChild, etc.) is fine but
I cannot save the modified file on the web server. The error I get is
"Permission denied". Many people say that I do not have a write permission
to the folder where the XML should be saved. I tried allowing all
permissions using FileZilla FTP Browser but it did not help at all. I
searched your site but could not find anything related. Is there a
workaround or is there another way to read and save XML files using
JavaScript?
  
  I hope you have time to answer another very very quick question. I am
taught that document.getDocumentById is cross-browser, so I don't see why we
need to consider the case of document.all like the following code found on
your DHTML tutorial page?
  
  function changeDisplay( elementId, setTo ) {
   var theElement;
    if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( elementId );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ elementId ];
  }
  ...
   
   
  Thank you very much. Please keep up the good work.
   
  Regards
FromMe
ToToan Nguyen
SubjectRe: saveXML does not work + why not only document.getElementById
Date9 November 2006 11:12
oan,

> I wanted to read and save an XML file the easiest way and so I used
> Microsoft's  proprietary XMLDOM object.

I never work with something that only works in IE. It breaks the Web for
everyone else, and that defies the very spirit that the Web was created in.

> Is there a workaround or is there another way to read and
> save XML files using JavaScript?

Although I personally dislike this dependence on scripting within the
client, if you want to do it, I recommend you try using XMLHttpRequest:
http://www.howtocreate.co.uk/tutorials/jsexamples/importingXML.html
You can load XML with it. There is also DOM Load And Save, but that is not
supported by enough browsers. The easiest way to save XML is to make an
XMLHttpRequest to the server, that uses POST instead of GET to pass a lot of
information back to the server

var foo;
if( window.XMLHttpRequest ) {
  foo = new XMLHttpRequest();
} else {
  try {
    try {
      foo = new ActiveXObject( 'Microsoft.XMLDOM' );
    } catch(e) {
      foo = new ActiveXObject( 'Msxml2.XMLHTTP' );
    }
  } catch(e) { /* failure to do anything */ }
}
foo.open('POST','bar.php',true);
foo.send(XMLdata);

> I hope you have time to answer another very very quick question. I am
> taught that document.getDocumentById is cross-browser, so I don't see
> why we need to consider the case of document.all like the following
> code found on your DHTML tutorial page?

That depends on what you call cross browser. I tend to go to extremes, but
in this case, it is for a good reason. getElementById works in all current
versions of major desktop browsers, and several minor browsers, and device
browsers. Using document.all extends support to some older versions, but
also to current versions of Internet Explorer for mobile phones and PDAs,
WebTV/MSNTV:
http://www.howtocreate.co.uk/tutorials/javascript/dhtml

Since you are manipulating XML, you are already shutting out those browsers
anyway, so it probably does not matter for you.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.