我这有一个xml的字符串var s="<root><Property Name='长'  Value='11' /><Property Name='宽'  Value='22' /><Property Name='属性三' ID='9ee7e7bc-1cdc-47c3-b856-09873c7190b4'  Value='E8E' /></root>"
我现在想得到下面结果的字符串
长=11,宽=22,属性三=E8E-----
不知道该用什么方法最好最快最方便实现

解决方案 »

  1.   

    先看看如何操作xml http://www.itwis.com/html/net/c/20090622/4737.html
      

  2.   

    快不敢说 纯粹个人练手!~
    var s="<root><Property Name='长'  Value='11' /><Property Name='宽'  Value='22' /><Property Name='属性三' ID='9ee7e7bc-1cdc-47c3-b856-09873c7190b4'  Value='E8E' /></root>";
    var reg = /<[^>]*?Name\s*=\s*['"](.*?)['"][^>]*?Value\s*=\s*['"](.*?)['"][^>]*?>/g,arr=[];
    while(reg.exec(s)!=null){
    arr.push(RegExp.$1+'='+RegExp.$2);
    }
    alert(arr)
      

  3.   

    楼上的不错,谢谢了,
    我自己搞了一个很挫的//递归接收一个字符串,返回属性和值
    //#region
    function MyRecursion(value, result) {    var connectStr = result;    var indexPropertyNameStart = value.indexOf("<Property Name='");
        //是否还有属性
        if (indexPropertyNameStart != -1) {        value = value.substring(indexPropertyNameStart + 16, value.length);
            var indexPropertyNameEnd = value.indexOf("'");        var propertyName = value.substring(0, indexPropertyNameEnd);        connectStr += propertyName + "=";        value = value.substring(indexPropertyNameEnd + 1, value.length);        var indexValueStart = value.indexOf("Value='");
            value = value.substring(indexValueStart + 7, value.length);        var indexPropertyValueEnd = value.indexOf("'");
            var propertyValue = value.substring(0, indexPropertyValueEnd);        value = value.substring(indexPropertyValueEnd + 1, value.length);        connectStr += propertyValue + ";";        return MyRecursion(value, connectStr);
        }    return connectStr;}
    //#endregion
    调用:var s = "<root><Property Name='长'  Value='11' /><Property Name='宽'  Value='22' /><Property Name='属性三' ID='9ee7e7bc-1cdc-47c3-b856-09873c7190b4'  Value='E8E' /></root>";
    var str = MyRecursion(s, "");