-
Designer, Programmer, Musician
-
.
Hi,
What is the code (*.fla) you are using to create your xml file, and by print do you mean print on paper on just viewing it
-
.
Hi,
Without seeing how you want it or how you are achieving it so far.
This might be of assistance to you,
PHP Code:
var xml:XML = <FirstNode/>;
var propertyAmount:Number = 5;
for (var i:int = 1; i <= propertyAmount; i++)
{
var nodeName:String = "Property" + i;
var isValue:String = "Value: " + i;
xml.appendChild(<{nodeName}>{isValue}</{nodeName}>);
}
trace(xml);
var saveXML:FileReference = new FileReference();
saveXML.save("<?xml version='1.0' encoding='utf-8'?>\n\n" + xml, "savedXML.xml");
-
Designer, Programmer, Musician
Originally Posted by fruitbeard
Hi,
Without seeing how you want it or how you are achieving it so far.
This might be of assistance to you,
PHP Code:
var xml:XML = <FirstNode/>;
var propertyAmount:Number = 5;
for (var i:int = 1; i <= propertyAmount; i++) { var nodeName:String = "Property" + i; var isValue:String = "Value: " + i; xml.appendChild(<{nodeName}>{isValue}</{nodeName}>); }
trace(xml);
var saveXML:FileReference = new FileReference(); saveXML.save("<?xml version='1.0' encoding='utf-8'?>\n\n" + xml, "savedXML.xml");
Yeah, that's exactly what i was doing, except this:
saveXML.save("<?xml version='1.0' encoding='utf-8'?>\n\n" + xml,
And i added that and i'm still getting all the nodes in the same line :/
This is my script:
PHP Code:
switch(e.currentTarget) { case b_save: var temp:XML = new XML(); temp.ignoreWhite= true; temp = <Usuario/>; temp.appendChild(<Nombre>{t_name.text}</Nombre>); temp.appendChild(<Edad>{t_age.text}</Edad>); temp.appendChild(<Pais>{t_country.text}</Pais>);
xml.appendChild(temp); trace(xml) fsave.save("\n"+xml, "myXML.xml"); break;
It works great, but in the XML file, all the nodes are put in the same line, and i need they to be
aligned one in top of the other.
I attach 2 pictures, one how it is supposed to looks like, and the other how it actually looks like, thanks so much for replying.
Correct
correct.JPG
Wrong
wrong.JPG
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
Designer, Programmer, Musician
Solved
SOLVED. I achieved it. I don't know if it's the best practice, but it does what i wanted:
Once the xml is constructed, we convert it to XML String this way:
PHP Code:
var newtext:String = xml.toXMLString();
Then, we replace all the "\n" with "\n\r" (this is the most important line of code, because this script will be sure that all the spaces will filled with the correct line breaks).
PHP Code:
newtext = newtext.split('\n').join('\r\n');
Finally, we make a new instance of the ByteArray class, and assign the string to it, so instead of writing the xml object into the XML file, we will write UTFBytes raw data:
PHP Code:
var bytes:ByteArray = new ByteArray();
bytes.writeUTFBytes(newtext);
And then we write it:
PHP Code:
fsave.save(bytes, "myXML.xml");
Now the nodes are perfectly aligned in the XML file if you open it with Notepad.
Picture:
finally.JPG
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
.
Hi,
or you could just use
var newXML:String = oldXML.toXMLString();
newXML = newXML.replace(/\n/g, "\r\n");
-
Designer, Programmer, Musician
Wow, that works great fruitbeard. No need of converting it to UTFBytes.
I was about to tell you to explain that, but then i read about the replace class and learned that "g" means global, the first and the last "/" symbol are the opening and closing of the regular expresion, and the "\n" is the string to search. Thanks so much have a nice day.
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
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
|