Reputation: 323
I have the following xml from a large xml file.
<Text>
<cp IX='0'/>
<pp IX='0'/>
<tp IX='0'/>Wo<cp IX='1'/>rl<cp IX='2'/>d<cp IX='3'/>
<cp IX='4'/>!!<cp IX='5'/>
</Text>
is there any way to access the text in between "cp" and "tp" nodes separately (ex: Wo, rl, d, !!)? I can get them as a single string but, I need them separately like in an array. Thanks..
Upvotes: 1
Views: 124
Reputation: 13645
You should get your <Text>
tag content as string and use split with regex:
var array:Array = textTagContent.split(/<\S*[^>]*>/);
trace(array) // ,,,Wo,rl,d,,!!,
Trim it!
a = trimArray(a);
Use it!
trace(a) // Wo,rl,d,!!
Trim function:
function trimArray(array:Array):Array {
var a:Array = [];
for each (var item in array)
{
if (item) {
a.push(item);
}
}
return a;
}
Upvotes: 0
Reputation: 2707
You can use the text() method on your XML property:
var myXML : XML = <Text>
<cp IX='0'/>
<pp IX='0'/>
<tp IX='0'/>Wo<cp IX='1'/>rl<cp IX='2'/>d<cp IX='3'/>
<cp IX='4'/>!!<cp IX='5'/>
</Text>
var text : String = myXML.text().toString();
trace (text); // output World!!
Upvotes: 1
Reputation: 6230
Basically Wo
, rl
, d
and !!
are children of Text
node. Their type is TEXT_NODE
.
So I would suggest to iterate over all Text
children, and store those which type is TEXT_NODE
as elements of an array.
Upvotes: 0