-
Convert XML to String
Hi everyone,
I'm trying to convert an variable that contains XML data to a String. Anyone have a clue on how to achieve this?
My main problem is that the XML data is formatted nicely, but I need to store it in the database without the linebreaks and tab stops and whitespaces.
I think converting it into string would work with .toString();, but that doesn't get rid of the XML formatting...
Thanks in advance!
Eddie
Last edited by EddiE_K2003; 08-10-2010 at 10:18 AM.
Learning flash, one frame at a time
-
Have you got an example of the data, are you trying to do this in flash or at the server side?
-
The data from Flash looks like
PHP Code:
<panels>
<panel>
<layout>
<panelId>0</panelId>
<defaultOn>1</defaultOn>
<alwaysOn>0</alwaysOn>
<hasTexts>1</hasTexts>
<hasPictures>0</hasPictures>
<hasMonograms>1</hasMonograms>
<canDIY>1</canDIY>
...
While I need the data to look like the following when inserting in the database:
PHP Code:
<?xml version="1.0"?><panels><panel><layout><panelId>0</panelId><defaultOn>1</defaultOn><alwaysOn>0</alwaysOn><hasTexts>1</hasTexts><hasPictures>0</hasPictures><hasMonograms>1</hasMonograms><canDIY>1</canDIY>
...
I want to send the XML data from Flash and save it in the database through PHP. The only accepted form I can add it in the database is the one in the second example, where there are no line breaks or tabs between tags.
I'm not having any issues with saving the data to the database, but I need in the first presented form.
There is a long way to do it, by going through each tag and concatenating each one to a new string, but I'm hoping there's an easier way.
Thanks!
Learning flash, one frame at a time
-
i use dot net on the server side so dont have a specific example to help you with but you could try a find and replace function which would replace the charCode for line breaks and tabs
-
Thanks gareth, I'll give your idea a go. Have tried doing that from PHP but was getting problems between converting wanted line breaks(inside tags) from unwanted line breaks(outside the tags). I'll try and do it from Flash and see what I end up with.
Thanks again!
Learning flash, one frame at a time
-
Hey,
I have the solution for you here. I played around with charCode some weeks ago:
Actionscript Code:
var string:String = xml.toString(); var formatedString:String = "";
for(var i:uint = 0; i < string.length; ++i) { if(string.charCodeAt(i) != 32 && string.charCodeAt(i) != 10) formatedString += string.charAt(i); }
trace(formatedString);
Last edited by radykal; 08-11-2010 at 05:07 AM.
-
Thanks alot radykal, I'll give it a go!
Learning flash, one frame at a time
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
|