-1

次のようなXML文字列があります

<?xml version="1.0" encoding="UTF-8"?>
<ProductDetails ProductID="TuscanWengeShoeRack010cfg" ProductcfgPath="http://localhost/media/productattachment/176/TuscanWengeShoeRack010cfg.xml" SKUID="TWS090" />

次の出力が必要です

var pid = // should be fetched from ProductcfgPath attribute
var sku = // should be fetched from SKUID attribute

alert(pid);  // 176
alert(sku);  // TWS090
4

1 に答える 1

0

解決した

var rawXmlString = '\<\?xml version = "1.0" encoding = "UTF-8" ?><ProductDetails ProductID="TuscanWengeShoeRack010cfg" ProductcfgPath="http://localhost/media/productattachment/176/TuscanWengeShoeRack010cfg.xml" SKUID="TWS090" />';
var $xmlJSObject = $.parseXML(rawXmlString);
var path = $($xmlJSObject).find('ProductDetails').attr('ProductcfgPath');
var sku = $($xmlJSObject).find('ProductDetails').attr('SKUID');

var numberArray = path.match(/(\d+)/g);
var pid = numberArray[0];

alert(pid);  // 176
alert(sku);  // TWS090
于 2015-09-01T07:15:55.943 に答える