I'm seeing something very very strange happening in a Flex app I'm maintaining.
I've been going through it removing all calls to trace() and replacing it with calls into the logging framework (using the built in mx.logging stuff). After doing so some XML parsing code suddenly broke, and I can't for the life of me figure out why.
here's the code:
private var loader:URLLoader; // created elsewhere
private function handleComplete(event:Event):void {
default xml namespace = com;
xml = XML(loader.data);
var response:XML = new XML(xml..raniResponse);
//now handles a null response object
if(xml && response.children().length() > 0) {
LOG.debug("Got response.");
var cityXML:XML = new XML(xml..city);
var stateXML:XML = new XML(xml..stateProv);
/* Some extra processing is done here */
}
}
With the code like this, with that LOG.debug() call in place, I get the following error on the line cityXML is defined:
TypeError: Error #1088: The markup in the document following the root element must be well-formed.
If I comment out the LOG.debug() call it works fine.
I thought there might be some weirdness with the custom log target I created, so I removed that. Currently the only target being used is the built-in trace target.
Does anyone know what's going on? Why would a logging call break the XML parsing? I can't think of anything it could be doing that would break it.
EDIT:
I did some more tests, and it's just getting weirder.
I changed the code based on David's comment to use xml..city[0] instead of new XML(xml..city) for both assignments. This caused the exception to happen a bit later (in some code not shown above where it's referencing cityXML). So I tried stepping through in the debugger and noticed something odd.
cityXML was being set to null, while stateXML was getting the proper value. Looking at the xml object in the debugger showed all the correct data, so it should have been fine. As a random test I rearranged the code so that stateXML was being loaded first. After doing that, stateXML is null, while cityXML is correct.
So, whichever assignment happens immediately after the log is failing, but whatever happens after that worked fine.
Here's the (somewhat sanitized) XML that's being parsed:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<com:MyCompanyRANIv.01 xmlns:com="com:myc:rani:1:0:message" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<com:raniResponse>
<com:telephonyInfo>
<com:countryCode>1</com:countryCode>
<com:telephoneNumber>14121234567</com:telephoneNumber>
</com:telephonyInfo>
<com:geoInfo>
<com:coordinates>
<com:latLon>
<com:lat>40.49</com:lat>
<com:lon>-79.92</com:lon>
</com:latLon>
</com:coordinates>
<com:countryInfo>
<com:country>
<com:featureName>United States</com:featureName>
<com:featureTypeDescription>United States of America</com:featureTypeDescription>
<com:featureCode value="US" system="ISO 3166" family="Country Code" systemVer="1-alpha-2" />
</com:country>
</com:countryInfo>
<com:stateProvInfo>
<com:stateProv>
<com:featureName>PENNSYLVANIA</com:featureName>
<com:featureTypeDescription xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureCode family="US State Code" system="FIPS State Alpha Code" systemVer="" value="PA" />
</com:stateProv>
</com:stateProvInfo>
<com:regionInfo>
<com:region>
<com:featureName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureTypeDescription xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureCode family="" system="" systemVer="" value="" />
</com:region>
</com:regionInfo>
<com:countyParishInfo>
<com:countyParish>
<com:featureName>ALLEGHENY</com:featureName>
<com:featureTypeDescription xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureCode family="" system="" systemVer="" value="" />
</com:countyParish>
</com:countyParishInfo>
<com:cityInfo>
<com:city>
<com:featureName>PITTSBURGH</com:featureName>
<com:featureTypeDescription xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureCode family="" system="" systemVer="" value="" />
</com:city>
</com:cityInfo>
<com:buildingInfo>
<com:building>
<com:featureName xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
<com:featureTypeDescription xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</com:building>
</com:buildingInfo>
<com:streetAddress address="" />
</com:geoInfo>
<com:services host="false" wireless="false" other="false" />
</com:raniResponse>
<com:raniRequest>
<com:fullyQualifiedTelephoneNumber>14121234567</com:fullyQualifiedTelephoneNumber>
</com:raniRequest>
</com:MyCompanyRANIv.01>
</soapenv:Body>
</soapenv:Envelope>