Skip to main content
Participant
August 8, 2010
Question

XML Processing Instructions

  • August 8, 2010
  • 2 replies
  • 1057 views

Hi,

I have two questions about how the XML class in AS3 works.
First, does the XML class care about the initial processing instruction when created from a string like this?:

<?xml version="1.0" encoding="UTF-8" ?>
<painting>
  <img src="madonna.jpg" alt='Foligno Madonna, by Raphael'/>
  <caption>This is Raphael's "Foligno" Madonna, painted in
    <date>1511</date><date>1512</date>.
  </caption>
</painting>

Second, how can I add that procession instruction to an XML object that I am working with so that toXMLString() returns a string that looks like the above XML? (So that it includes the processing instruction.)

This topic has been closed for replies.

2 replies

Inspiring
August 8, 2010

1. this xml is badly formed - you will get errors. If you use special characters - use CDATA block.

2. AS3 parser doesn't care for initial processing instructions except for encoding.

3. If you need to preserve initial instructions for display - don't parse it and use string directly.

Inspiring
August 8, 2010

Hi!

Normally you won't see processing instructions when working with AS3 and XML but you can change that using the following line of code:

XML.ignoreProcessingInstructions = false;

If you will, you can also see your comments by using the following:

XML.ignoreComments = false;

I think it's usual to use those lines inside your package body, even before your imports but I think you could have it anywhere else (even outside your package body I think).

Hope it helps.

edit: don't forget you can manage those items as a  XMLList too...