有关xml文件中createTextNode的问题 [英] Question about createTextNode in xml files

查看:97
本文介绍了有关xml文件中createTextNode的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个空标签,例如< p id =" pid">< / p>在xml文件中。并且,我有一个

脚本作为傻瓜:


str ="< b> Hello World !!!< / b>" ;;

ele = documeny.getElementById(" pid");

ele.appendChild(document.createTextNode(str));


我希望看到Hello World !!!用粗体字母,但我看到

"< b> Hello World !!!< / b>"。


我尝试更换/与\ /,但这没有帮助。然后我试着用

替换<与& LT;和>与& GT;但是那没用,那么

我试过替换<与\u 003e和>用\ 003c,但那也没有b $ b工作。显示确切的字符串而不是Hello

World !!!用粗体字母表示。


html文件没有问题。 FireFox和IE都以

粗体字母显示。


任何提示都将受到赞赏。


非常感谢提前。


DK Mishra

解决方案

DKM写道:

我有一个空标签,如< p id =" PID">< / p为H.在xml文件中。而且,我有一个像傻瓜一样的脚本:

str ="< b> Hello World !!!< / b>" ;;
ele = documeny。 getElementById(" pid");
ele.appendChild(document.createTextNode(str));




这将创建一个值为文字字符串

"< b> Hello World !!!< / b>" ;.


如果您期望HTML< B个元素包含文字Hello

World !!!然后你需要创建B元素并将文本放在

中:


< script type =" text / javascript">

函数sayHelloWorld(){

var str =''Hello World !!!'';

var ele = document.getElementById(''pid '');

var b = document.createElement(''B'');

b.appendChild(document.createTextNode(str));

ele.appendChild(b);

}

< / script>

< input type =" button" value ="添加''Hello World''" onclick ="

sayHelloWorld();

">

< div id =" pid">< / div>


[...]


-

Rob





RobG写道:

DKM写道:

我有一个空标签,如< p ID = QUOT; PID">< / p为H.在xml文件中。而且,我有一个像傻瓜一样的脚本:

str ="< b> Hello World !!!< / b>" ;;
ele = documeny。 getElementById(" pid");
ele.appendChild(document.createTextNode(str));
这将创建一个文本节点,其值为文字字符串
"< b> ; Hello World !!!< / b>"。

如果您期望HTML< B>包含文字Hello
World !!!的元素然后你需要创建B元素并将文本放在
中:

< script type =" text / javascript">
函数sayHelloWorld(){
var str =''Hello World !!!'';
var ele = document.getElementById(''pid'');
var b = document.createElement(''B'' );
b.appendChild(document.createTextNode(str));
ele.appendChild(b);
}
< / script>



我是从一个java applet里面做的那样,但是由于我们在java applet中创建了一个html格式化的字符串,所以我在一个java applet中创建了一个html格式的字符串

并将其传递给javascript。任何崩溃都没有

。现在,问题是将html格式的字符串

插入到文档中。


任何关于如何动态插入long和compleex html的想法

格式化文件中的字符串?


非常感谢提前。


DK Mishra

< input type =" button" value ="添加''Hello World''" onclick ="
sayHelloWorld();
">
< div id =" pid">< / div>

[。 ..]

-
Rob




DKM写道:


RobG写道:

DKM写道:

我有一个空标签,如< p id =" pid" ;>< / p为H.在xml文件中。而且,我有一个像傻瓜一样的脚本:

str ="< b> Hello World !!!< / b>" ;;
ele = documeny。 getElementById(" pid");
ele.appendChild(document.createTextNode(str));
这将创建一个文本节点,其值为文字字符串
"< b> ; Hello World !!!< / b>"。

如果您期望HTML< B>包含文字Hello
World !!!的元素那么你需要创建B元素并将文本放在
中:



[...]我是从java applet中做到的,但由于LiveConenct的错误特性,我在java小程序中创建一个html格式的字符串
并将其传递给javascript。没有任何崩溃,这一直在稳健地工作。现在,问题是将html格式化的字符串
插入到文档中。

任何想法如何动态地将长和完整的html
格式化字符串插入到文档中?


然后我猜你会遇到innerHTML,但请注意它不是W3C DOM的一部分。
< blockquote class =post_quotes>< input type =" button" value ="添加''Hello World''" onclick ="
sayHelloWorld();
">
< div id =" pid">< / div>




< input type =" button" value ="添加''Hello World''" onclick ="


var s =''< b> Hello World !!!< / b>'';

document.getElementById( ''pid'')。innerHTML = s;


">

< div id =" pid">< / div> ;


-

Rob


I have an empty tag like <p id="pid"></p> in a xml file. And, I have a
script as foolows:

str = "<b>Hello World!!!</b>";
ele = documeny.getElementById("pid");
ele.appendChild(document.createTextNode(str));

I expected to see "Hello World!!!" in bold letters, but instead I see
"<b>Hello World!!!</b>".

I tried replacing / with \/, but that did not help. Then I tried
replacing < with & lt ; and > with & gt ;, but that did not work, then
I tried replacing < with \u 003e and > with \u 003c, but that did not
work too. The exact string is being displayed instead of "Hello
World!!!" in bold letters.

There is no problem with html files. Both FireFox and IE display in
bold letters.

Any tip will be appreciated.

Thanks very much in advance.

D.K. Mishra

解决方案

DKM wrote:

I have an empty tag like <p id="pid"></p> in a xml file. And, I have a
script as foolows:

str = "<b>Hello World!!!</b>";
ele = documeny.getElementById("pid");
ele.appendChild(document.createTextNode(str));



This will create a text node with a value of the literal string
"<b>Hello World!!!</b>".

If you are expecting an HTML <B> element containing the text "Hello
World!!!" then you need to create the B element and put the text inside
it:

<script type="text/javascript">
function sayHelloWorld(){
var str = ''Hello World!!!'';
var ele = document.getElementById(''pid'');
var b = document.createElement(''B'');
b.appendChild(document.createTextNode(str));
ele.appendChild(b);
}
</script>
<input type="button" value="Add ''Hello World''" onclick="
sayHelloWorld();
">
<div id="pid"></div>

[...]

--
Rob




RobG wrote:

DKM wrote:

I have an empty tag like <p id="pid"></p> in a xml file. And, I have a
script as foolows:

str = "<b>Hello World!!!</b>";
ele = documeny.getElementById("pid");
ele.appendChild(document.createTextNode(str));
This will create a text node with a value of the literal string
"<b>Hello World!!!</b>".

If you are expecting an HTML <B> element containing the text "Hello
World!!!" then you need to create the B element and put the text inside
it:

<script type="text/javascript">
function sayHelloWorld(){
var str = ''Hello World!!!'';
var ele = document.getElementById(''pid'');
var b = document.createElement(''B'');
b.appendChild(document.createTextNode(str));
ele.appendChild(b);
}
</script>



I was doing that from inside a java applet, but due to buggy nature of
LiveConenct, I am creating a html formated string in the java applet
and passing it to javascript. That has been working robustly without
any crash. Now, the problem is to insert that html formatted string
into the document.

Any idea as to how one can dynamically insert a long and compleex html
formated string into the document?

Thanks very much in advance.

D.K. Mishra
<input type="button" value="Add ''Hello World''" onclick="
sayHelloWorld();
">
<div id="pid"></div>

[...]

--
Rob




DKM wrote:


RobG wrote:

DKM wrote:

I have an empty tag like <p id="pid"></p> in a xml file. And, I have a
script as foolows:

str = "<b>Hello World!!!</b>";
ele = documeny.getElementById("pid");
ele.appendChild(document.createTextNode(str)) ;
This will create a text node with a value of the literal string
"<b>Hello World!!!</b>".

If you are expecting an HTML <B> element containing the text "Hello
World!!!" then you need to create the B element and put the text inside
it:


[...] I was doing that from inside a java applet, but due to buggy nature of
LiveConenct, I am creating a html formated string in the java applet
and passing it to javascript. That has been working robustly without
any crash. Now, the problem is to insert that html formatted string
into the document.

Any idea as to how one can dynamically insert a long and compleex html
formated string into the document?

Then I guess you''re stuck with innerHTML, but be aware that it is not
part of the W3C DOM.

<input type="button" value="Add ''Hello World''" onclick="
sayHelloWorld();
">
<div id="pid"></div>



<input type="button" value="Add ''Hello World''" onclick="

var s = ''<b>Hello World!!!</b>'';
document.getElementById(''pid'').innerHTML = s;

">
<div id="pid"></div>

--
Rob


这篇关于有关xml文件中createTextNode的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆