473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

xml parsing and text replacement

Hi all!

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>

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?

Thanks for any advice!

Rob
:)
Jul 19 '05 #1
3 1482


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/

Jul 19 '05 #2
Martin Honnen wrote on 29 feb 2004 in
microsoft.public.inetserver.asp.general:
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:


If it is only a ontime task, you could use VBS replace:

txt = Replace(txt,
"<from id=""123"">Jani</from>","<from id=""123"">New author</from>")

Regex replace is also an option.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3
Thank you Martin and Evertjan - your advice was very helpful!

Rob
:)

"Martin Honnen" <Ma***********@t-online.de> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl...


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/

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: XspiriX | last post by:
Hi I am new here and so in python :-) I am trying to make a script for extracting (parsing?) some values from a file and write them into an output i thought to follow this example (cookbook): ...
3
by: RogerTBrick | last post by:
Cheers for the help last time guys. Again this is probably dead simple but try as I might, I just can't work it out. THe XML file I am being give contains some code value that need to be...
1
by: Philippe Poulard | last post by:
hi, i have the following fragment : ****** <?xml version="1.0"> Begin <elem/> End ******
9
by: gov | last post by:
Hi, I've just started to learn programming and was told this was a good place to ask questions :) Where I work, we receive large quantities of data which is currently all printed on large,...
29
by: zoltan | last post by:
Hi, The scenario is like this : struct ns_rr { const u_char* rdata; }; The rdata field contains some fields such as :
4
by: Max | last post by:
I am writing a XML parser in Javascript and i have difficulty to understand the specifics of some "entities". I would want to understand the way in which the non-validating XML Parsers manage...
6
by: Tuomas Rannikko | last post by:
Hello, I'm currently writing a XML processor for the fun of it. There is something I don't understand in the spec though. I'm obviously missing something important. The spec states that both...
31
by: David Cramer | last post by:
If you had an application that you were about to begin development on which you wanted to be cross platform (at least Mac and Windows), would you suggest using c++ and Python? I'm asking because...
1
by: Robert Neville | last post by:
Basically, I want to create a table in html, xml, or xslt; with any number of regular expressions; a script (Perl or Python) which reads each table row (regex and replacement); and performs the...
3
by: jcassan | last post by:
Hello folks. I am new to these forums and have something, which has been stumping me for little while. I am using pspell to spellcheck a scrolling textbox (textarea) containing user input. I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.