-
[as3.0]
Hi everybody
I would like to change tag order in my xml file... based on the tag <order>
for example I have xml file
<?xml version="1.0" encoding="UTF-8"?>
<list>
<material>
<title>Something 2</title>
<order>2</order>
</material>
<material>
<title>Something 3</title>
<order>3</order>
</material>
<material>
<title>Something 1</title>
<order>1</order>
</material>
</list>
and after some action script actions I would like to get something like this
<?xml version="1.0" encoding="UTF-8"?>
<list>
<material>
<title>Something 1</title>
<order>1</order>
</material>
<material>
<title>Something 2</title>
<order>2</order>
</material>
<material>
<title>Something 3</title>
<order>3</order>
</material>
</list>
anyone can help me???
-
PHP Code:
var xml:XML = <list>
<material>
<title>Something 2</title>
<order>2</order>
</material>
<material>
<title>Something 3</title>
<order>3</order>
</material>
<material>
<title>Something 1</title>
<order>1</order>
</material>
</list>;
var arr:Array = [];
for each(var mat in xml.material) arr.push({node:mat,order:mat.order});
arr.sortOn("order");
var newXML:XML = <list></list>;
for(var i:int=0;i<arr.length;i++) newXML.appendChild(arr[i].node);
trace(newXML);
-
thanks a lot... that was exacly what I was lookin' for
and one more question how should I modify Your code to do something like that:
when the order node is empty it should be placed at the end of queue... example
<?xml version="1.0" encoding="UTF-8"?>
<list>
<material>
<title>Something 3</title>
<order>3</order>
</material>
<material>
<title>Something empty</title>
<order></order>
</material>
<material>
<title>Something 2</title>
<order>2</order>
</material>
</list>
and the result should be
<?xml version="1.0" encoding="UTF-8"?>
<list>
<material>
<title>Something 2</title>
<order>2</order>
</material>
<material>
<title>Something 3</title>
<order>3</order>
</material>
<material>
<title>Something empty</title>
<order></order>
</material>
</list>
Last edited by s2472; 05-25-2009 at 03:57 AM.
-
change this:
PHP Code:
arr.push({node:mat,order:mat.order});
to this:
PHP Code:
arr.push({node:mat,order:mat.order.toString()||Infinity});
-
thank You once again...
-
-
ok one more thing hopefully the last one...
<?xml version="1.0" encoding="UTF-8"?>
<list>
<material>
<title>Ewolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jajEwolucja smoczych jaj</title>
<order>10</order>
</material>
<material>
<title>Eastwood za kamer</title>
<order></order>
</material>
</list>
if my title tag has above 40chars I would like to replace him into this tag first 40characters and then three dots... I have something like this I have almost everything but I don't know how two replace tag
PHP Code:
for each (var property:XML in newXML.material)
{
var titleXML:String = String(property.title);
if (titleXML.length > 40)
{
var shortenTitleXML:String = titleXML.substr(0,39);
var shortenTitleXMLDots:String = shortenTitleXML + "...";
//and know the replacement
}
}
Last edited by s2472; 05-25-2009 at 04:02 PM.
-
PHP Code:
for each (var property:XML in newXML.material)
{
var titleXML:String = String(property.title);
if (titleXML.length > 40)
{
var shortenTitleXML:String = titleXML.substr(0,39);
var shortenTitleXMLDots:String = shortenTitleXML + "...";
// add this
property.title = shortenTitleXMLDots;
}
}
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|