More issues with XML


(TaylorAnderson) #1

Hey again. I’m having yet another problem with XML, specifically accessing its elements with a nested loop. This is the code I have now:

	var convoXml:XML = FP.getXML(xml);
	var list:XMLList = convoXml.Message
	var element:XML;
	
	var i:Number = 0;
	var j:Number = 0;
	
	for each(element in list)
	{
		messagesArr[i] = new Message(element.@Content)
		var list2:XMLList = element.Response
		var element2:XML;
		for each(element2 in list2)
		{
			messagesArr[i].AddResponse(new Response(element2.@Content, element2.@Value), j)
			j++
		}
		i++
	}

This does not seem to be setting the responses right I was gonna post this as a response to my earlier topic about XML because it already had the XML document typed out within it, but there was some formatting issues so I’ll just post the XML here again:

<?xml version="1.0" encoding="utf-8"?>

<Conversations>
  <Message Content="This is a test message.">
    <Response Content="This is a test response 1" Value="0" />
    <Response Content="This is a test response 2." Value="1" />
    <Response Content="This is a test response 3." Value="2" />
  </Message>
  <Message Content="This is test message 2">
    <Response Content="This is the first response." Value="0" />
    <Response Content="This is the second response" Value="1" />
    <Response Content="This is the third response" Value="2" />
  </Message>
  <Message Content="This is test message 3">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 4">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content=" Test 5">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 6">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 7">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 8">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 9">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
  <Message Content="Test 10">
    <Response Content="" Value="" />
    <Response Content="" Value="" />
    <Response Content="" Value="" />
  </Message>
</Conversations>

(azrafe7) #2

It’s late here and I’ll better get off to sleep, but I noticed you’re missing quite a bunch of ; (not that they’re part of the problem, but it seemed weird :wink: ).

About the issue instead: one can easily deduce that messageArr is an Array (or Vector), but of what?

If you can give us some more info about your source we will surely find it easier to isolate the problem (well… at least we’ll try to).

I recall having problems with XML just because the string returned were empty for some reason, not sure if this can be the case, but you can try to trace the retrieved values to see if they’re what you expect.

I’ll check this topic tomorrow… 'night!

EDIT: Also… you’re not resetting j to zero out of the inner loop (still don’t know if you need it to, in your AddResponse()). I’ll run a test tomorrow if I have time. 'Night again!

EDIT2: Wait wait wait… are you getting only the first message correctly but not the others?


(TaylorAnderson) #3

OH MAN! zeroing out j seems to be working! You are a lifesaver I was getting so tired of this problem. Thanks so much!


(azrafe7) #4

Ha, great!

You’re welcome! :wink: