A
andyashton
How can I create a new XML object for processing using only elements
from a certain namespace? If I have a file like this:
<?xml version="1.0" encoding="UTF-8"?>
<sports xmlnslayer="http://www.mlb.com/players">
<sport>Baseball</sport>
<league>MLB</league>
<playerlayer>
<player:name>Derek Jeter</player:name>
<playerosititon>Shortstop</playerosition>
</playerlayer>
<playerlayer>
<player:name>Andy Pettite</player:name>
<playerosititon>Pitcher</playerosition>
</playerlayer>
</sports>
I think I should be able to access those elements in the 'player'
namespace like this:
// parse with E4X
var p = new Namespace("http://www.mlb.com/players");
// why does this default namespace declaration not work!?
var xml = new XML(text);
if(xml.p:layer.length()) {
var playersElements = xml.p:layer;
} else {
var playersElements = [xml];
}
for each(var players in playersElements) {
....process those elements...
}
But it doesn't seem to work. Can anyone point out where I'm going
wrong?
Thanks!
from a certain namespace? If I have a file like this:
<?xml version="1.0" encoding="UTF-8"?>
<sports xmlnslayer="http://www.mlb.com/players">
<sport>Baseball</sport>
<league>MLB</league>
<playerlayer>
<player:name>Derek Jeter</player:name>
<playerosititon>Shortstop</playerosition>
</playerlayer>
<playerlayer>
<player:name>Andy Pettite</player:name>
<playerosititon>Pitcher</playerosition>
</playerlayer>
</sports>
I think I should be able to access those elements in the 'player'
namespace like this:
// parse with E4X
var p = new Namespace("http://www.mlb.com/players");
// why does this default namespace declaration not work!?
var xml = new XML(text);
if(xml.p:layer.length()) {
var playersElements = xml.p:layer;
} else {
var playersElements = [xml];
}
for each(var players in playersElements) {
....process those elements...
}
But it doesn't seem to work. Can anyone point out where I'm going
wrong?
Thanks!