Skip to main content
Participant
March 15, 2007
Question

insertHTML won't work with XML files

  • March 15, 2007
  • 4 replies
  • 763 views
I am trying to create a command that writes text to an open XML file. The command I've created works fine under some circumstances but not others.

It works if I open an XML file and apply the command without editing the file. If I make any edits to the file manually and then apply the command, it doesn't insert anything.

It works fine with HTML files in design view, but in code view, if I make any edits and then run the command, nothing happens. If I switch to design view and back again, the command then works fine.

I tested the built-in Dreamweaver command "Flash Text" on an XML file (after editing it so it could be used with an XML file), and the same problem occurs with this command when using it on an XML file. The problem didn't occur with HTML in code view, though.

Below is the .JS file for my command. The corresponding HTML file contains only an empty form.

function canAcceptCommand() {
return(true);
}

function isDOMRequired() {
return false;
}

function commandButtons()
{
return new Array( MM.BTN_OK, "cmdOK(); "
, MM.BTN_Cancel, "cmdCancel();");
}

function cmdOK()
{
var theDOM = dw.getDocumentDOM('document');
theDOM.insertHTML("test", true);
window.close();

}

function cmdCancel()
{
window.close();
}
This topic has been closed for replies.

4 replies

Inspiring
March 15, 2007
Yes it is a defualt command. Be sure you access it through Program Files --> Macromedia --> Dreamweaver 8 --> Configuration --> Commands.
Participant
March 15, 2007
I have DW 8 at home, so I'll check this out tonight or tomorrow. Maybe it's a bug in DW MX. Thanks for all your suggestions.
Inspiring
March 15, 2007
Take a look at the "Mark of the Web.js" located in the commands folder. This is very similar to what it sounds like you are doing.
Participant
March 15, 2007
I don't seem to have that file in my setup. Is that a feature that was added in Dreamweaver 8?
Inspiring
March 15, 2007
DWfile.write(), or dreamweaver.createXMLDocument() are the ones I use to maniulate XML files. But I never tried to apply a command to an XML document, normally I just write to one, or create it.
Participant
March 15, 2007
I need a function, though, that will insert text at the cursor location in an open file.

I'm also discovering that the command I created above functions erratically even when it does deign to insert the text in an XML file. The text is usually inserted somewher other than where the cursor is located.
Inspiring
March 15, 2007
Everything looks good. I don't see anything that pops out at me that could be causing your problem. I have never tried inserting HTML into an XML file, so I don't kow if that is allowed or not.
Participant
March 15, 2007
Would there be any other function besides insertHTML that could possibly be used to insert text into an XML file? insertText won't work, because it converts the characters.

I'm using Dreamweaver MX 2004, by the way.