XML error at ampersand (&)

后端 未结 5 1881
迷失自我
迷失自我 2020-11-29 07:29

I have a php file which prints an xml based on a MySql db.

I get an error every time at exactly the point where there is an & sign.

Here

5条回答
  •  猫巷女王i
    2020-11-29 08:02

    Switch and regex with using xml escape function.

     function XmlEscape(str) {
        if (!str || str.constructor !== String) {
            return "";
        }
    
        return str.replace(/[\"&><]/g, function (match) {
            switch (match) {
            case "\"":
                return """;
            case "&":
                return "&";
            case "<":
                return "<";
            case ">":
                return ">";
            }
        });
    };
    

提交回复
热议问题