【问题标题】:Issue while parsing xml in AngularJs在 AngularJs 中解析 xml 时出现问题
【发布时间】:2022-01-16 19:01:45
【问题描述】:

我正在尝试将下面提到的字符串解析为 XML 格式。

var postData = '<wfs:Transaction service="WFS" version="1.0.0"'+
  'xmlns:topp="http://www.openplans.org/topp"'+
  'xmlns:ogc="http://www.opengis.net/ogc"'+
  'xmlns:wfs="http://www.opengis.net/wfs">'+
  '<wfs:Update typeName="Sample:ebs">'+
    '<wfs:Property>'+
      '<wfs:Name>tp</wfs:Name>'+
      '<wfs:Value>'+populationvalue+'</wfs:Value>'+
    '</wfs:Property>'+
    '<ogc:Filter>'+
      '<ogc:FeatureId fid="'+this.selectedEBS+'"/>'+
    '</ogc:Filter>'+
  '</wfs:Update>'+
'</wfs:Transaction>'

我正在使用下面的代码来做到这一点。

parser = new DOMParser();
xmlDoc = parser.parseFromString(postData, "text/xml");

但是这样做时我收到了这个错误:

第 1 行第 47 列的错误:属性构造错误

【问题讨论】:

    标签: xml xml-parsing xmlhttprequest


    【解决方案1】:

    属性之间没有空格:

    改变

    '<wfs:Transaction service="WFS" version="1.0.0"'+
      'xmlns:topp="http://www.openplans.org/topp"'+
    

    '<wfs:Transaction service="WFS" version="1.0.0"'+
      ' xmlns:topp="http://www.openplans.org/topp"'+
    

    等等

    【讨论】:

      【解决方案2】:

      我的坏我的坏

      我忘了包含\n

      var postData = '<wfs:Transaction service="WFS" version="1.0.0"\n'+
        'xmlns:topp="http://www.openplans.org/topp"\n'+
        'xmlns:ogc="http://www.opengis.net/ogc"\n'+
        'xmlns:wfs="http://www.opengis.net/wfs">\n'+
        '<wfs:Update typeName="Sample:ebs">\n'+
          '<wfs:Property>\n'+
            '<wfs:Name>tp</wfs:Name>\n'+
            '<wfs:Value>'+populationvalue+'</wfs:Value>\n'+
          '</wfs:Property>\n'+
          '<ogc:Filter>\n'+
            '<ogc:FeatureId fid="'+this.selectedEBS+'"/>\n'+
          '</ogc:Filter>\n'+
        '</wfs:Update>\n'+
      '</wfs:Transaction>\n
      

      '

      【讨论】:

        猜你喜欢
        • 2021-12-15
        • 1970-01-01
        • 2011-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        相关资源
        最近更新 更多