Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

javascript - parse variable to xml

I would like to parse my variable "valueStations2" into a xml string. Instead of a static sos:FeatureOfInterestId value (here e.g. "stationname") I would like to have a dynamic parsed from javascript. I tried setting my variable in quotes like "valueStation2" for "stationname" but xml does not except. I would like to know how to add a variable to xml. Any suggestions?

  var valueStation2;

  var xml = "<?xml version='1.0' encoding='UTF-8'?> 
  <sos:GetFeatureOfInterestTime     
     xmlns:sos='http://www.opengis.net/sos/1.0' 
     service='SOS' version='1.0.0' 
     xmlns:ows='http://www.opengeospatial.net/ows'> 
     <sos:FeatureOfInterestId>stationname</sos:FeatureOfInterestId> 
  </sos:GetFeatureOfInterestTime>";

// create handler
var request = OpenLayers.Request.POST({
    url: "http://139.17.3.301:8080/mydata/sos",
    data: xml,
    callback: handler
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this:

 var valueStation2;

 var xmlString = "<?xml version='1.0' encoding='UTF-8'?> 
 <sos:GetFeatureOfInterestTime xmlns:sos='http://www.opengis.net/sos/1.0' service='SOS' version='1.0.0' xmlns:ows='http://www.opengeospatial.net/ows'> 
      <sos:FeatureOfInterestId>" + valueStation2 + "</sos:FeatureOfInterestId> 
 </sos:GetFeatureOfInterestTime>";

 var xmlParser = new DOMParser();
 var xmlDOM = xmlParser.parseFromString(xmlString, "text/xml");

Wrapping any variable with quotes will turn it into a string which is not what you're looking for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...