Robert Mark Bram wrote:
I want to use asp to do text find and replace with XHTML elements.. for
example, let's say I have the following XHTML:
<note>
<from id="123">Jani</from>
<to>Tove</to>
<message>Norwegian: æøå. French: êèé</message>
</note>
That is XML but not XHTML.
I want to read this document in, find and XML element with id="123" and
replace its text with "New author".
Can I do this in ASP?
Yes, using MSXML:
<%@ Language="JScript" %>
<%
var xmlDocument = Server.CreateObject("Msxml2.DOMDocument.4.0");
xmlDocument.async = false;
var loaded = xmlDocument.load(Server.MapPath("test20040229.xml" ));
if (loaded) {
xmlDocument.setProperty("SelectionLanguage", "XPath");
var from = xmlDocument.selectSingleNode("/note/from[@id = '123']");
if (from) {
from.text = "New Author";
}
Response.ContentType = "text/xml";
xmlDocument.save(Response);
}
else {
Response.Write("<p>Error loading XML document: " +
xmlDocument.parseError.reason + ".<\/p>");
}
%>
The script uses MSXML 4 which usually needs to be installed, look on
msdn.microsoft.com for the download.
Or change the 4.0 to 3.0 and it should work on machines where IE6 is
installed
--
Martin Honnen
http://JavaScript.FAQTs.com/