Home > Back-end >  Issue while parsing xml in AngularJs
Issue while parsing xml in AngularJs

Time:01-16

I am trying to parse below mentioned string to XML format.

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

I am using below code to do so.

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

but I'm getting this error when doing so:

error on line 1 at column 47: attributes construct error

CodePudding user response:

There's no whitespace between the attributes:

Change

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

to

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

etc.

CodePudding user response:

My Bad My bad

I forgot to include \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

'

  •  Tags:  
  • Related