[haXe] XML nodeType enum
Zjnue Brzavi
zjnue.brzavi at googlemail.com
Mon Nov 6 23:13:34 CET 2006
Hi Keith,
I played with some Xml routines a while ago. I managed with Std.string
as you mentioned. Just checked and it still compiles fine with haXe
1.08. Here is a snippet:
static function stripNodes( x : Xml ) : Xml {
var nodeVal;
for ( i in x ) {
switch ( Std.string( i.nodeType ) ) {
case Std.string( Xml.PCData ) :
nodeVal = stripWhite( i.nodeValue );
if ( nodeVal == "" ) {
x.removeChild( i );
} else {
i.nodeValue = nodeVal;
}
case Std.string( Xml.Element ) :
i = stripNodes( i );
default :
x.removeChild( i );
}
}
return x;
}
Hope it helps,
Zjnue
On 11/6/06, Keith Hall <kingkeith at gmail.com> wrote:
> Hello list,
>
> I've just been trying to upgrade a project from HaXe 1.07 to 1.08, and I'm
> having trouble with the new way the compiler handles enums. Previously, I
> was able to use a switch statement to check the nodeType of an XML node:
> switch (node.nodeType) { // where node is an instance of Xml
> case Xml.Element:
> // do something related to the element
> case Xml.PCData:
> // do something related to the text
> }
>
> but now it gives me a complier error saying invalid enum handling.
>
> Perhaps, if the class used the XmlType enum properly - instead of statically
> from the Xml class, then this would no longer be a problem. Also, with the
> way the enum itself is left blank, one can't then get any errors when one of
> the enum properties is missing from the switch statement. But presumably it
> is like that for a reason? If so, perhaps someone could give me the reason,
> and tell me a suitable workaround?
>
> I'm thinking I could wrap the switched property and all the enums in an
> Std.string call? What do you think about that? Or is there a better method
> I'm missing, as this wouldn't solve the missing enum non-error?
>
> Thanks for your time
> Keith Hall
> --
> haXe - an open source web programming language
> http://haxe.org
>
>
More information about the Haxe
mailing list