加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

记录导致XML解析中断?

发布时间:2020-12-16 22:48:48 所属栏目:百科 来源:网络整理
导读:我正在看一些我正在维护的Flex应用程序中发生的非常奇怪的事情. 我一直在通过它删除对trace()的所有调用,并将其替换为对日志框架的调用(使用内置的mx.logging内容).这样做之后,一些XML解析代码突然破了,我不能为我的生活找出原因. 这是代码: private var lo
我正在看一些我正在维护的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>

解决方法

这是一个艰难的.我从来没有使用过日志类,所以我不确定问题的那一部分,但是像你一样将XMLList转换为XML:

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

仅当XMLList包含单个项目时才起作用,否则您将收到引用的警告.请尝试以下表格:

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

这适用于空列表以及包含许多项的列表.您还可以使用xml..city.length()检查子项的数量,如果不是1,则记录警告消息.这可能有助于找出确切的问题.

但是,如何通过添加或删除日志记录调用来实现这一点,打败了我.

(在一个有点相关的说明中,我注意到在switch语句的case块中声明和赋值给XML变量不能按预期工作,即简单地忽略赋值,并且不会为变量赋值.两行中的帮助.这对我来说似乎也是一个错误,所以在AS3中编译与XML相关的代码可能不是一切都正确.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读