xml4c子节点 [英] xml4c child nodes

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

问题描述

我正在尝试遍历子节点列表。好像要获得节点的文本值,你必须做一个

node-> getFirstChild() - > getNodeValue。这就是说,有一个

hasChildNodes方法,但如果我使用它,它包括text和text。节点

也是,我不想要包括。


如果这是我的xml:


< A>

< B>< / B>

< C>< / C>

< / A>


如果我有一个B节点,我认为getNextSibling会返回C,但它没有。\\ b
没有。返回#text。


困惑。

I''m trying to iterate through a list of child nodes. It seems like to
get the text value of the node, you have to do a
node->getFirstChild()->getNodeValue. This being said, there is a
hasChildNodes method, but if I use that, it includes the "text" nodes
also, which I don''t want ot include.

if this is my xml:

<A>
<B></B>
<C></C>
</A>

if I have a node for B, I thought getNextSibling would return C, but it
didn''t. it returned #text.

confused.

推荐答案

ma ***** @ yahoo.com 写道:

< A>

< B>< / B>

< C>< / C>

< / A>


如果我有一个B节点,我认为getNextSibling会返回C,但是它没有b $ b。它返回了#text。
<A>
<B></B>
<C></C>
</A>

if I have a node for B, I thought getNextSibling would return C, but it
didn''t. it returned #text.



如果你停下来查看那个文本节点的值,你会得到

回答你自己的问题 - - 这是B'的结束标记和C的开始标记之间的空格(换行符和

缩进)。


XML不知道这个空白文本是否有意义,所以

XML API将提供它。你的应用需要妥善处理。

-

()ASCII Ribbon Campaign | Joe Kesselman

/ \标记HTML电子邮件! |系统架构和动态诗歌

If you''d stopped to look at the value of that text node, you''d have
answered your own question -- it''s the whitespace (newline and
indentation) between the B''s end-tag and the start-tag for C.

XML doesn''t know whether that whitespace text is meaningful or not, so
XML APIs will deliver it. Your app needs to deal with that appropriately.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry


Joe Kesselman写道:
Joe Kesselman wrote:

XML不知道是否有空白文本是否有意义,所以

XML API将提供它。您的应用需要妥善处理。
XML doesn''t know whether that whitespace text is meaningful or not, so
XML APIs will deliver it. Your app needs to deal with that appropriately.



某些XML API可能会将此类空白报告为可忽略。这是DTD不允许PCDATA的元素之间的空格.b
$ b。这个

假设有一个DTD。


但它们仍然是信息集中的节点。

// Magnus

Some XML APIs may report such whitespace as "ignorable". This is
whitespace between elements where the DTD does not allow PCDATA. This
assumes that there is a DTD.

But they are still nodes in the infoset.
// Magnus




ma*****@yahoo.com 写道:


ma*****@yahoo.com wrote:

我正在尝试迭代子节点列表。好像要获得节点的文本值,你必须做一个

node-> getFirstChild() - > getNodeValue。这就是说,有一个

hasChildNodes方法,但如果我使用它,它包括text和text。节点

也是,我不想要包括。


如果这是我的xml:


< A>

< B>< / B>

< C>< / C>

< / A>


如果我有一个B节点,我认为getNextSibling会返回C,但它没有。\\ b
没有。它返回了#text。
I''m trying to iterate through a list of child nodes. It seems like to
get the text value of the node, you have to do a
node->getFirstChild()->getNodeValue. This being said, there is a
hasChildNodes method, but if I use that, it includes the "text" nodes
also, which I don''t want ot include.

if this is my xml:

<A>
<B></B>
<C></C>
</A>

if I have a node for B, I thought getNextSibling would return C, but it
didn''t. it returned #text.



然后检查nodeType(分别是getNodeType()),直到找到

元素节点(节点类型为1)。


-


Martin Honnen
http://JavaScript.FAQTs.com/


这篇关于xml4c子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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