Logging, resulting in XML parsing?

I see something very strange in the Flex application that I support.

I looked through this, removing all calls to trace () and replacing them with calls in the logging framework (using the built-in mx.logging material). After that, some XML syntax code suddenly broke, and I can’t understand for life why.

here is 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 code like this, with a call to LOG.debug (), I get the following error in the cityXML line:

 TypeError: Error #1088: The markup in the document following the root element must be well-formed. 

If I comment on the call to LOG.debug (), it works fine.

I thought there might be some kind of weirdness with the target target log I created, so I deleted it. Currently, the only target is inline tracing.

Does anyone know what is going on? Why does a log call interrupt XML parsing? I can’t think of anything that could do this, it would break him.

EDIT:

I did some more tests and it just got weirder.

I changed the code based on David's comment to use xml..city [0] instead of the new XML (xml..city) for both purposes. This caused the exception to happen a bit later (in some code, which is not shown above, where it refers to cityXML). So I tried to go through the debugger and noticed something strange.

CityXML was set to null, and stateXML was getting the correct value. Looking at the xml object in the debugger, it showed all the correct data, so everything should be fine. As a random test, I rebuilt the code so that stateXML is loaded first. After that, stateXML is null, and cityXML is correct.

So, no matter what the appointment was made immediately after the failure of the log, but everything that happens after that worked fine.

Here is a (somewhat sanitized) XML that is 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> 
+4
source share
3 answers

Posting this as an answer instead of editing, as it includes some workarounds.

I did some more tests. Here is the corresponding code from the first:

 LOG.debug("Got response:"); var cityXML:XML = xml..city[0]; var stateXML:XML = xml..stateProv[0]; 

After going through the debugger, cityXML is set to null, and stateXML gets the correct value.

Next I tried this:

 LOG.debug("Got response:"); trace("foobar"); var cityXML:XML = xml..city[0]; var stateXML:XML = xml..stateProv[0]; 

It worked! (What for?!). Both cityXML and stateXML received the correct values.

Not satisfied with this, I tried another test. I thought, maybe I just needed another operation between the magazine and the first task (I don’t know WHY, but just experiment here). So I tried this:

 LOG.debug("Got response:"); var someDumbVariable:Number = 42; var cityXML:XML = xml..city[0]; var stateXML:XML = xml..stateProv[0]; 

This did not work. So one more test:

 LOG.debug("Got response:"); var cityXML:XML = xml..city[0]; cityXML = xml..city[0]; var stateXML:XML = xml..stateProv[0]; 

It worked! When switching to the debugger, the first assignment ends with the cityXML value being null. However, the second assignment gives it the correct meaning. (I tried just breaking the cityXML line into an ad on one line and assigning it to another, but that didn't change the behavior. 2 assignments seemed necessary).

Another workaround:

 LOG.debug("Got response:"); if(xml.length() == 0) { return; } var cityXML:XML = xml..city[0]; var stateXML:XML = xml..stateProv[0]; 

I still don’t know why the log will cause this material to happen, but it seems that either a trace throw or an attempt to the task double-work around this problem. I will continue the investigation to find out if I can find out the reason here, but at least I now have a couple of workarounds that are not related to deleting the log.

+1
source

That's cool. I have never used logging classes, so I'm not sure about this part of the question, but I am converting an XMLList to XML like you:

 var cityXML:XML = new XML(xml..city); 

only works if the XMLList contains one element, otherwise you will get the warning you specified. Instead, try using the following form:

 var cityXML:XML = xml..city[0]; 

This works for empty lists as well as for lists with many elements. You can also check the number of children with xml..city.length() and write a warning if it is not 1. Perhaps this will help figure out the exact problem.

How this happens, adding or removing logging calls, however, beats me.

(In a related note, I noticed that declaring and assigning a value to an XML variable in the case block of a switch statement does not work properly, that is, assignment is simply ignored and the variable will not assign a value. Breaking a line in two helps. It also seemed to me an error, therefore, perhaps not everything is correct with compiling the XML in AS3.)

+1
source

Hm. This is very similar to the issue I mentioned. Try this: move XML variable declarations to the top of the function:

 private function handleComplete(event:Event):void { var cityXML:XML; var stateXML:XML; 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."); cityXML = new XML(xml..city); stateXML = new XML(xml..stateProv); /* Some extra processing is done here */ } } 

(Refers to as a separate answer, because it is very different from the previous one).

0
source

All Articles