Xml nodeValue

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Xml nodeValue

Dmitry Kosarev
Hello!

let look at  this xml: "<b>asdf<i>qwer</i></b>"
I can access `asdf` something like

var nodeType = Std.string(node.nodeType);
if (nodeType == "element") node.firstChild().toString() else node.nodeValue;

But for another xml : "<i><b>iiiiii</b></i> "
if statement above returns "<b>iiiiii</b>".
I have absolutely no ideas about how to check existance of node like `asdf` in first xml.


Any ideas?

Best wishes,
Kakadu
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Xml nodeValue

clemos
Hi

What do you mean by "existance of node like `asdf` ?
Your first XML contains one text node and one element, so its
firstChild is the text node (asdf)
Your second XML contains only one element, so its firstChild is this
element (<b>iiiiii</b>)

So you may want to iterate through all children of your element,
instead of grabbing only the firstChild.
This can be done by iterating directly on the node itself :
for(c in node )

Cheers
Clément

On Tue, Sep 13, 2011 at 1:35 PM, Dmitry Kosarev
<[hidden email]> wrote:

> Hello!
>
> let look at  this xml: "<b>asdf<i>qwer</i></b>"
> I can access `asdf` something like
>
> var nodeType = Std.string(node.nodeType);
> if (nodeType == "element") node.firstChild().toString() else node.nodeValue;
>
> But for another xml : "<i><b>iiiiii</b></i> "
> if statement above returns "<b>iiiiii</b>".
> I have absolutely no ideas about how to check existance of node like `asdf` in first xml.
>
>
> Any ideas?
>
> Best wishes,
> Kakadu
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

HA: [haXe] Xml nodeValue

Dmitry Kosarev
Where did you find such term as `text node`? I look at http://haxe.org/api/xml ant see only CData,  Comment, DocType, Document, Element, PCData, Prolog  node types.

I'll try to iterate directly immediatly. thanks.

Best wishes,
Kakadu
________________________________________
От: [hidden email] [[hidden email]] от имени clemos [[hidden email]]
Отправлено: 13 сентября 2011 г. 15:55
Кому: The haXe compiler list
Тема: Re: [haXe] Xml nodeValue

Hi

What do you mean by "existance of node like `asdf` ?
Your first XML contains one text node and one element, so its
firstChild is the text node (asdf)
Your second XML contains only one element, so its firstChild is this
element (<b>iiiiii</b>)

So you may want to iterate through all children of your element,
instead of grabbing only the firstChild.
This can be done by iterating directly on the node itself :
for(c in node )

Cheers
Clément

On Tue, Sep 13, 2011 at 1:35 PM, Dmitry Kosarev
<[hidden email]> wrote:

> Hello!
>
> let look at  this xml: "<b>asdf<i>qwer</i></b>"
> I can access `asdf` something like
>
> var nodeType = Std.string(node.nodeType);
> if (nodeType == "element") node.firstChild().toString() else node.nodeValue;
>
> But for another xml : "<i><b>iiiiii</b></i> "
> if statement above returns "<b>iiiiii</b>".
> I have absolutely no ideas about how to check existance of node like `asdf` in first xml.
>
>
> Any ideas?
>
> Best wishes,
> Kakadu
> --
> haXe - an open source web programming language
> http://haxe.org
>
--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: HA: [haXe] Xml nodeValue

clemos
Hi,

What I mean by text nodes is PCData (I think).
BTW, if you wish to spend a good time on the list, I suggest you setup
your mail system to use "standard" reply titles (and not "HA:").

Cheers,
Clément

2011/9/13 Dmitry Kosarev <[hidden email]>:

> Where did you find such term as `text node`? I look at http://haxe.org/api/xml ant see only CData,  Comment, DocType, Document, Element, PCData, Prolog  node types.
>
> I'll try to iterate directly immediatly. thanks.
>
> Best wishes,
> Kakadu
> ________________________________________
> От: [hidden email] [[hidden email]] от имени clemos [[hidden email]]
> Отправлено: 13 сентября 2011 г. 15:55
> Кому: The haXe compiler list
> Тема: Re: [haXe] Xml nodeValue
>
> Hi
>
> What do you mean by "existance of node like `asdf` ?
> Your first XML contains one text node and one element, so its
> firstChild is the text node (asdf)
> Your second XML contains only one element, so its firstChild is this
> element (<b>iiiiii</b>)
>
> So you may want to iterate through all children of your element,
> instead of grabbing only the firstChild.
> This can be done by iterating directly on the node itself :
> for(c in node )
>
> Cheers
> Clément
>
> On Tue, Sep 13, 2011 at 1:35 PM, Dmitry Kosarev
> <[hidden email]> wrote:
>> Hello!
>>
>> let look at  this xml: "<b>asdf<i>qwer</i></b>"
>> I can access `asdf` something like
>>
>> var nodeType = Std.string(node.nodeType);
>> if (nodeType == "element") node.firstChild().toString() else node.nodeValue;
>>
>> But for another xml : "<i><b>iiiiii</b></i> "
>> if statement above returns "<b>iiiiii</b>".
>> I have absolutely no ideas about how to check existance of node like `asdf` in first xml.
>>
>>
>> Any ideas?
>>
>> Best wishes,
>> Kakadu
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org