Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
日志记录导致XML解析中断?_Xml_Apache Flex_Actionscript 3_Logging - Fatal编程技术网

日志记录导致XML解析中断?

日志记录导致XML解析中断?,xml,apache-flex,actionscript-3,logging,Xml,Apache Flex,Actionscript 3,Logging,我在维护的Flex应用程序中看到了一些非常奇怪的事情 我已经完成了删除对trace()的所有调用,并将其替换为对日志框架的调用(使用内置的mx.logging工具)。在这样做之后,一些XML解析代码突然中断,我一辈子都不知道为什么 代码如下: private var loader:URLLoader; // created elsewhere private function handleComplete(event:Event):void { default xml namesp

我在维护的Flex应用程序中看到了一些非常奇怪的事情

我已经完成了删除对trace()的所有调用,并将其替换为对日志框架的调用(使用内置的mx.logging工具)。在这样做之后,一些XML解析代码突然中断,我一辈子都不知道为什么

代码如下:

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 */
  }
}
使用类似这样的代码,调用LOG.debug()后,在cityXML定义行上出现以下错误:

TypeError: Error #1088: The markup in the document following the root element must be well-formed.
如果我注释掉LOG.debug()调用,它就可以正常工作

我认为我创建的自定义日志目标可能有些奇怪,所以我删除了它。当前使用的唯一目标是内置跟踪目标

有人知道发生了什么事吗?为什么日志调用会破坏XML解析?我想不出它会做什么来打破它

编辑:

我做了更多的测试,结果越来越奇怪了

我根据David的评论更改了代码,将xml..city[0]而不是新的xml(xml..city)用于这两个赋值。这导致异常稍后发生(在上面未显示的一些代码中,它引用了cityXML)。所以我试着进入调试器,发现了一些奇怪的东西

cityXML被设置为null,而stateXML正在获取正确的值。在调试器中查看xml对象时显示了所有正确的数据,因此应该没有问题。作为一个随机测试,我重新安排了代码,以便首先加载stateXML。这样做之后,stateXML为null,而cityXML是正确的

因此,无论在日志失败之后立即发生什么分配,但在日志失败之后发生的任何分配都可以正常工作

下面是正在解析的(经过一定程度净化的)XML:

<?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>

1.
14121234567
40.49
-79.92
美国
美利坚合众国
宾夕法尼亚
阿勒格尼
匹兹堡
14121234567

这是个棘手的问题。我从未使用过日志类,所以我不确定问题的这一部分,但像您一样将XMLList转换为XML:

var cityXML:XML = new XML(xml..city);
仅当XMLList包含单个项时有效,否则您将收到您引用的警告。请尝试以下表单:

var cityXML:XML = xml..city[0];
这适用于空列表以及包含许多项的列表。您还可以使用
xml..city.length()
检查子项的数量,如果不是1,则记录警告消息。也许这将有助于找出确切的问题

然而,添加或删除日志调用是如何实现这一点的,这让我感到困惑


(有一点相关,我注意到在switch语句的
case
块中声明XML变量并为其赋值并不像预期的那样有效,也就是说,赋值被忽略,变量也不会被赋值。将行分成两行会有帮助。这对我来说似乎也是一个bug,所以可能不是所有的hing在AS3中编译XML相关代码是正确的。

将此作为答案而不是编辑,因为它包含一些解决方法

我还做了一些测试。以下是第一部分的相关代码:

LOG.debug("Got response:");
var cityXML:XML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
逐步使用调试器,cityXML被指定为null,而stateXML获得正确的值

接下来,我尝试了这个:

LOG.debug("Got response:");
trace("foobar");
var cityXML:XML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
LOG.debug("Got response:");
var someDumbVariable:Number = 42;
var cityXML:XML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
它成功了!(为什么?!)。cityXML和stateXML都得到了正确的值

对此不满意,我尝试了另一个测试。我想我可能只是需要在日志和第一个任务之间进行一些其他操作(不知道为什么,但只是在这里进行实验)。因此我尝试了以下方法:

LOG.debug("Got response:");
trace("foobar");
var cityXML:XML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
LOG.debug("Got response:");
var someDumbVariable:Number = 42;
var cityXML:XML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
这不起作用。所以,还有一个测试:

LOG.debug("Got response:");
var cityXML:XML = xml..city[0];
cityXML = xml..city[0];
var stateXML:XML = xml..stateProv[0];
这很有效!当使用调试器单步执行时,第一个赋值以cityXML设置为null结束。但是,对它的第二个赋值给出了正确的值。(我尝试简单地将cityXML行拆分为一行上的声明和另一行上的赋值,但这并没有改变行为。似乎需要两个赋值)

另一个解决方法:

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

我仍然不知道为什么日志会导致这种情况发生,但似乎要么抛出跟踪,要么尝试两次分配都能解决这个问题。我将继续调查,看看是否能找出根本原因,但至少我现在有了一些解决方法,不涉及删除日志。

嗯。这看起来与我提到的问题非常相似。请尝试以下操作:将XML变量声明移到函数的开头:

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 */
  }
}

(作为一个单独的答案发布,因为它与前一个答案大不相同。)

您可以发布您试图记录的XML吗?查看正在解析的XML,只有一个“城市”节点。与从中提取的其他内容相同。因此理论上XML转换应该可以正常工作。理论上,是的。但XML处理可能存在一些错误,正如我指出的,这就是为什么我建议尝试另一种表示法。尝试没有害处。:-)是的,我尝试过。它将错误移到代码中的其他地方。我更新了问题的细节。没有,行为没有改变。我认为它与变量关系不大,而与访问XML关系更大。由于某种原因,第一次尝试访问它时无法正常工作。因为我的