Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with quote marks from XML file

Contributor ,
Feb 12, 2010 Feb 12, 2010

I'm reading in an XML file generated from FileMaker Pro. The data is coming in fine except for the quotes around dialogue. Instead of getting quote marks, Flash will display " instead. I tried turning HTML text on, but that didn't help either. Any idea what I could try? Here is the code I'm using to read in the XML data:

var xmlString:URLRequest = new URLRequest("sim.xml");

var xmlLoader:URLLoader = new URLLoader(xmlString);

xmlLoader.addEventListener("complete", init);

function init(event:Event):void{

  var xDoc:XMLDocument = new XMLDocument();

  xDoc.ignoreWhite = true;

  var simXML:XML = XML(xmlLoader.data);

  xDoc.parseXML(simXML.toXMLString());

  // do a for loop to get all the data... //

  for (var i:int=0;i<=xDoc.firstChild.childNodes[4].childNodes.length-1; i++) {

backgroundArray.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[0].childNodes[0].childNodes[0]);

descriptionArray.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[1].childNodes[0].childNodes[0]);

choice1Array.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[2].childNodes[0].childNodes[0]);

choice2Array.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[3].childNodes[0].childNodes[0]);

choice3Array.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[4].childNodes[0].childNodes[0]);

choice4Array.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[5].childNodes[0].childNodes[0]);

titleArray.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[19].childNodes[0].childNodes[0]);

videoArray.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[20].childNodes[0].childNodes[0]);

}

  gotoAndPlay(3);

}

TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

why are you doing all those conversions starting with converting to an xmldocument?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2010 Feb 12, 2010

This is going to be a decision-based simulation where the user will be directed to a different scene depending on which option they choose. I am creating the content for each scene in FileMaker Pro, which makes it very easy to construct each scene. When all the scenes are constructed there, I simply export an XML file for Flash to read. Flash will reuse the same interface and replace the content. The idea here is to create something that can be duplicated by someone who does not have to know much about Flash.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

that didn't answer the question.  so, if you don't have a reason to do all those conversions use:

var simXML:XML = new XML();
simXML.ignoreWhitespace = true;

var xmlString:URLRequest = new URLRequest("sim.xml");
var xmlLoader:URLLoader = new URLLoader(xmlString);
xmlLoader.addEventListener("complete", init);

function init(event:Event):void {
    simXML = XML(xmlLoader.data);
    // do a for loop to get all the data... /
    for (var i:int=0; i<=simXML.firstChild.childNodes[4].childNodes.length-1; i++) {
        backgroundArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[0].childNodes[0].childNodes[0]);
        descriptionArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[1].childNodes[0].childNodes[0]);
        choice1Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[2].childNodes[0].childNodes[0]);
        choice2Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[3].childNodes[0].childNodes[0]);
        choice3Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[4].childNodes[0].childNodes[0]);
        choice4Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[5].childNodes[0].childNodes[0]);
        titleArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[19].childNodes[0].childNodes[0]);
        videoArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[20].childNodes[0].childNodes[0]);
    }
    gotoAndPlay(3);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2010 Feb 12, 2010

Sorry, I misunderstood what you were getting at.

It doesn't seem to be loading anything at all with the code you provided. There don't seem to be a lot of differences between our code other than the name of the object, the order, and that my code has the line

xDoc.parseXML(simXML.toXMLString());

but maybe it needs that due to my initiating the XMLDocument object:

var xDoc:XMLDocument = new XMLDocument();

whereas your code is:

var simXML:XML = new XML();

I don't really have a good handle on understanding this stuff yet.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 12, 2010 Feb 12, 2010

Perhaps if you posted the XML you're working with it would give a clearer picture of what you're trying to accomplish.  Without seeing it, though, my thought is you might want to wrap the text with quotes in a CDATA tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

well, you need to load the xml file.  you didn't show that code so i reasoned that wasn't a problem for you.

someplace you should have:

simXML.load(xmlString);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2010 Feb 12, 2010

Here are my original files if that helps:  http://www.personal.psu.edu/pzb4/simulation/

the zipped file will allow you to download them all (including the FLA) or you can view the PeerTutor.html file to see what it looks like. It's not quite working yet, however. Also having an issue with it loading the next videos after the first one.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

i generally don't download and correct files unless i'm hired.  that shouldn't be necessary for this problem.

however, if you a number of problems you want corrected you may want to hire me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 12, 2010 Feb 12, 2010

I posted the files since SolitonMan suggested I put the xml file up. Just wanted to show what I was trying to accomplish. I don't expect everyone to do my work for me. Just wanted some help in figuring out why the quotes don't show up right. Where would I put the CDATA tags?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2010 Feb 12, 2010

cdata tags are used within a node tags (but aren't needed for quotes):

<tag><![CDATA[this will work:  <showme>]]></tag>

<tag>this would not work:  <showmc></tag>

<tag>this would work:  "showme"</tag>

p.s.  if you use the code i suggested, your quotes will appear correctly.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 15, 2010 Feb 15, 2010

I believe the XMLDocument object is the culprit in the quotes not showing up properly, however, I'm still having an issue with getting the XML to parse proprely with your code, kglad. I've slightly modified it to include some error tracing and it says it can't parse the XML, which makes me think it's the style of my XML doc that FMP makes. Here is the code I'm using now:

var simXML:XML = new XML();

simXML.ignoreWhitespace = true;

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE,init,false,0,true);

xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);

xmlLoader.load(new URLRequest("sim.xml"));

function init(evt:Event):void {

    simXML = XML(xmlLoader.data);

    try {

for (var i:int=0; i<=simXML.firstChild.childNodes[4].childNodes.length-1; i++) {// backgroundArray.push(xDoc.firstChild.childNodes[4].childNodes.childNodes[0].childNodes[0].childNodes[0]);

descriptionArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[1].childNodes[0].childNodes[0]);

choice1Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[2].childNodes[0].childNodes[0]);

choice2Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[3].childNodes[0].childNodes[0]);

choice3Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[4].childNodes[0].childNodes[0]);

                 choice4Array.push(simXML.firstChild.childNodes[4].childNodes.childNodes[5].childNodes[0].childNodes[0]);

               choice1DestinationArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[6].childNodes[0].childNodes[0]);

                choice2DestinationArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[7].childNodes[0].childNodes[0]);

                choice3DestinationArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[8].childNodes[0].childNodes[0]);

               choice4DestinationArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[9].childNodes[0].childNodes[0]);

               questionArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[18].childNodes[0].childNodes[0]);

               titleArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[19].childNodes[0].childNodes[0]);

               videoArray.push(simXML.firstChild.childNodes[4].childNodes.childNodes[20].childNodes[0].childNodes[0]);

               }

          } catch (err:Error) {

     trace("Could not parse loaded content as XML:\n" + err.message);

          }

}

function onIOError(evt:IOErrorEvent):void {

trace("An error occurred when attempting to load the XML file.\n"+ evt.text);

}

I get the "Could not parse" message. My XML document breaks up all content into COL tags which contain the content within DATA tags for everything like this:

<RESULTSET FOUND="20">

−

<ROW MODID="11" RECORDID="1">

−

<COL>

<DATA>background.jpg</DATA>

</COL>

−

<COL>

−

<DATA>

You are a tutor at the Writing Center. Because of the "open door" policy in the center, a tutor is always available to work with students who drop in. It has been a quiet afternoon and you have been catching up on some of your Biology lab work. You have just about finished writing the answer a question when a student enters the room, slumps loudly into a chair, and drops his backpack on the floor. He is wearing a baseball cap, chewing gum, blowing bubbles, and listening to music through ear buds. As he slumps in the chair he crosses his arms and frowns. He taps his foot and looks around the room.

</DATA>

</COL>

−

<COL>

<DATA>A.  "Hi, are you looking for someone?"</DATA>

</COL>

−

<COL>

−

<DATA>

B.  "Hi, sorry to keep you waiting.  I’m Alex. Looks like you’ve had a rough day. How can I help you?"

</DATA>

</COL>

−

<COL>

−

<DATA>

C.  "Is this your first time here?  Do you have an appointment?"

</DATA>

</COL>

−

Just not sure how to translate that into the data I need. The push statements I'm using don't seem to be working for the XML object. It works fine for the XMLDocument object, though. Any idea how to modify the push statement?

Thanks, I do appreciate your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 17, 2010 Feb 17, 2010
LATEST

This worked:

var simXML:XML = new XML();

simXML.ignoreWhitespace=true;

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.addEventListener(Event.COMPLETE,init,false,0,true);

xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);

xmlLoader.load(new URLRequest("sim.xml"));

function init(evt:Event):void {

simXML=XML(xmlLoader.data);

try {

for (var i in simXML.RESULTSET.ROW.COL) {

trace("data = " + simXML.RESULTSET.ROW.COL.DATA[0]);

backgroundArray.push(simXML.RESULTSET.ROW.COL.elements("DATA"));

trace("background = " + backgroundArray);

}

} catch (err:Error) {

trace("Could not parse loaded content as XML:\n" + err.message);

}

}

function onIOError(evt:IOErrorEvent):void {

trace("An error occurred when attempting to load the XML file.\n"+ evt.text);

}

It also involved removing the xmlns attribute from the FMPXMLRESULT tag in the XML doc for some reason. Would not load at all with that attribute present.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines