View Full Version : Flash + XML processing instructions
sparkrobot
06-09-2006, 11:33 PM
I have to use a product called Documentum to publish documents to our
webserver. I'm having an issue with it inserting processing
instructions to my xml document as show below:
<pic>
<image>
<?dctmEditor
selectedPath=/wcs_images/graphics/adventures/photos/gal_00.jpg
?>
<?dctmLink
chronic_id=0900029a800c829b object_id=0900029a800c829b edit_widget_type=graphic
?>
/graphics/adventures/photos/gal_00.jpg
</image>
</pic>
This breaks Flash, but works with the original XML file which
indicates <image> as:
<pic>
<image>/graphics/adventures/photos/gal_00.jpg</image>
</pic>
I'm looking for pointers on how I might strip the xml processing
instructions from the xml with AS, or at least ignore them. Has anyone
run into this before and by chance have a solution?
Try stripping the question marks out of your xml doc.
sparkrobot
06-12-2006, 06:07 PM
Thanks for your reply. I need to remove those instructions from the XML document with Flash. The CMS system we are locked into inserts the processing instructions seemingly arbitrarily into the xml files we've uploaded. To clarify, I need to strip out this from my xml document before as it is loaded into Flash:
<?dctmEditor
selectedPath=/wcs_images/graphics/adventures/photos/gal_00.jpg
?>
<?dctmLink
chronic_id=0900029a800c829b object_id=0900029a800c829b edit_widget_type=graphic
?>
Is there an approach you can recommend to remove these strings from the xml document with actionscript? Basically removing "<?" and "?>" and everything between.
acolyte
06-14-2006, 12:22 AM
Hi Sparkrobot ,
no this can`t be done . The Flash xmlparser doesnt read your xmlfile.
You need to alter something @ your (cms)Domphp script to generate a valid xml structure .
greets Aco
sparkrobot
06-14-2006, 12:29 AM
thanks for the reply. i think you're right. it's not looking good on this. <sigh>
Well it can be done, it will be difficult though. The methods of the String class in Flash are not that great, but with some clever scripting you could write a custom class that would effectively strip the text between two points, which is what you want to do. This is something I have struggled with in the past, but I am going to see if I can write a class to do this. I'll let you know how it goes...
sparkrobot
06-14-2006, 08:01 AM
I came across this Regular Expressions class (http://www.jurjans.lv/flash/RegExp.html) on the web, I'm going to take a closer look at it tomorrow. Thanks for your help on this.
Hey I think I may have your solution... there isn't much code, so rather than just uploading an .as file, I'll walk you through how to make it yourself.
In Flash, open a new ActionScript file and copy this code into it:
class StringParser {
public function StringParser() {
}
public function stripString(string:String, Start:String, End:String):String {
var sArray = string.split(Start);
var newString = sArray[0].toString();
for (var p = 1; p<sArray.length; p++) {
newString += sArray[p].substr((sArray[p].toString().indexOf(End)+End.length));
}
return newString;
}
}
Save this file as StringParser.as in the same directory of the site you are working on.
In your .fla, when you define xml.onLoad add this code:
yourXML.onLoad = function(){
var myParser:StringParser = new StringParser();
stripped = myParser.stripString(this.toString(), "<?", "?>");
newXML = new XML(stripped);
}
Let me know if this works! I have only tested it with a test string and not an XML doc, but, it does strip everything between the tags indicated and return a string without them. In theory then, you should be able to pass that string into a new XML constructor and hence, your 'newXML' variable will be a valid xml object without your unwanted tags.
acolyte
06-14-2006, 09:33 AM
Hi Hooj & sparkrobot,
NO please not!
dear Mr. Expert there is also a Error here :
<?xml version='1.0' encoding='UTF-8'?>
<pic>
<image>
<?dctmEditor selectedPath='/wcs_images/graphics/adventures/photos/gal_00.jpg'?>
<?dctmLink chronic_id='0900029a800c829b' object_id='0900029a800c829b' edit_widget_type='graphic'?>
</image>
</pic>
the apostrophes ('') are missing @ the attributes values, thus it would make much more sens to output a valid xml(>>with Apostrophes surrounding the attributes values<<) from the cms than
stripping characters.
Well , dont trust in me you can choose Hoojs way of stripping out Characters but it would make it unneccesarily complicated
in the best case this dude should look like :
<?xml version='1.0' encoding='UTF-8'?>
<pic>
<image>
<dctmEditor selectedPath='/wcs_images/graphics/adventures/photos/gal_00.jpg'></dctmEditor>
<dctmLink chronic_id='0900029a800c829b' object_id='0900029a800c829b' edit_widget_type='graphic'></dctmLink>
</image>
</pic>
http://www-128.ibm.com/developerworks/opensource/library/os-xmldomphp/
greets m@
sparkrobot
06-14-2006, 08:27 PM
Thanks for the idea hooj. I'm going to try this today.
acolyte, while I appreciate your post, I must indicate I have no control over what the cms outputs. I understand it's malformed, but in this case, I only have control of the swf.
ybull
06-16-2006, 12:18 PM
I believe you could get around this by using onData instead of onLoad.
onData is called with the server response, then if it is valid XML it creates the XML object and then calls onLoad.
So, try using onData, remove the unwanted sections and then call onLoad yourself. (as defining your own onData method overrides the default)
acolyte
06-19-2006, 09:10 AM
Hi ybull ,
thnx for your replie .
Just one short Question .
How to detect the attributes values lenght then to "strip" in the attributes values '' apostrophys.
thnx M@
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.