Click to See Complete Forum and Search --> : setting xml tag


thisObject
08-16-2005, 09:59 PM
Hey yall,

I've been struggling with the problem I have for while. Would appreciate if somebody can help me out on this.

I have a frameset of two xml pages.
First page has: <Title>Blah.</Title>
Second Page: <Link>Click meLink>

When user click the link on second page it should change
<Title>Blah.</Title> to <Title>Here you go.</Title>

After that I am as a user should see the change on the screen.

Code I have:

xml page:
...
<PageHeader Id="asdf">
<Title>Blah.</Title>
...

JavaScript function:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("main_page.xml");
nodes=xmlDoc.documentElement.childNodes;

nodes(0).getElementsByTagName('PageHeader')[0].firstChild.text = "asdf";
alert(nodes(0).getElementsByTagName('PageHeader')[0].firstChild.text);
alert(nodes(0).getElementsByTagName('PageHeader')[0].firstChild.xml);

So from the second alert window I can see that the <Title> tag is getting set.
HOWEVER, this is the problem the page on the browser window does not change. Do I need to refresh or something like this?

Thank you.

sheila
08-17-2005, 01:21 PM
Why do you want to change the title of the first page?

thisObject
08-17-2005, 03:06 PM
Well, it is a tag name which displays this text in certian format (bold, italics and so on).

sheila
08-17-2005, 04:25 PM
If you save the change to the title as part of the process of changing the xml then refreshing the page should update what you see in the browser.

If you don't save the change then refreshing the browser window would still show no change as you would be loading the original (unchanged) xml.

thisObject
08-17-2005, 06:19 PM
How can I save the change? Why doesn't it work with XML and works perfectly with HTML? Because XML has to be transalted by XSL? Thanks.

sheila
08-17-2005, 06:48 PM
As far as I can see, all your alerts are doing is returning existing values from the xml. How are you actually changing the value of <title />?

It would help if you showed actual script extracts rather than the abbreviated version you've provided.

thisObject
08-17-2005, 08:07 PM
this is the code that sets <Title>
nodes(0).getElementsByTagName('PageHeader')[0].firstChild.text = "asdf";

It is a big xml page and I use the code above to get needed node and then I set it to "asdf".

sheila
08-18-2005, 08:34 AM
Are you changing the value of <title /> before or after you've output the xml into the browser window?

thisObject
08-19-2005, 12:44 PM
after.
First I see both pages in a frameset. Then I click a link, <Title> tag is being set and then I need to see the change. So, I am changing the value of the tag AFTER I have the output the xml into the browser window.
:)

sheila
08-19-2005, 01:28 PM
Then you need to either refresh the page or use DHTML to display the change.

thisObject
08-19-2005, 02:15 PM
ok,

I tried refreshing the page but then new value of <Title> gets replaced by old one. Therefore, I guess I need to save xml document. Correct? If so how can I do that?

Also, how can I use DHTML to display the change?

thisObject
08-19-2005, 02:39 PM
thank you for following up, Sheila :)

sheila
08-19-2005, 03:08 PM
I've never used JavaScript to save XML but I think this should work:

xmlDoc.save("main_page.xml")

As for using DHTML, you'll need to read up on it. W3Schools (http://www.w3schools.com/htmldom/default.asp) is a good place to start.

thisObject
08-19-2005, 09:05 PM
Thank you. I will try it out and let you know how it goes.

thisObject
08-22-2005, 12:23 PM
Can I actually use the above save function if I use client-side JavaScript?
I do not think I can do it since it is client-side.
So, what should I do?

thisObject
08-22-2005, 01:49 PM
Nevermind Sheila,

I figure out what the problem is :) Finally!
Thank you very much for all your help.