关于取一段字符串中的一段xml的问题?
橱窗的光
橱窗的光 2017-03-06 09:48:12
0
2
1018
Blockly.Blocks['kjh'] = {
  init: function() {
    this.appendDummyInput().appendField('kjh');
    this.setOutput(true, null);
    this.setColour(164);
    this.setTooltip('');
    this.setHelpUrl('');
  }
};
Blockly.JavaScript['kjh'] = function(block) {
      var code = 'gdfnh';
      return [code, Blockly.JavaScript.ORDER_NONE];
}
<xml xmlns="http://www.w3.org/1999/xhtml">
    <block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block>
</xml>

请问如何取这段字符串中的xml部分?非常感谢!

橱窗的光
橱窗的光

Antworte allen(2)
数据分析师

关于取一段字符串中的一段xml的问题?-PHP中文网问答-关于取一段字符串中的一段xml的问题?-PHP中文网问答

围观一下哦,学习一下。

迷茫

遇到这种我的一般做法是利用replace+正则来提取。

var t = `Blockly.Blocks['kjh'] = {
  init: function() {
    this.appendDummyInput().appendField('kjh');
    this.setOutput(true, null);
    this.setColour(164);
    this.setTooltip('');
    this.setHelpUrl('');
  }
};
Blockly.JavaScript['kjh'] = function(block) {
      var code = 'gdfnh';
      return [code, Blockly.JavaScript.ORDER_NONE];
}
<xml xmlns="http://www.w3.org/1999/xhtml">
    <block type="variables_get" id="EaezE9)%*e^B{Olq7?Le" x="147" y="34"></block>
</xml>`;

var res;

t.replace(/<xml[^<>]+>[\s\S]*?<\/xml>/,function(e){
    res = e;
    return e
});

这里主要一个正则是关于这段文本如果有回车换行的情况,直接用.*并不能直接匹配,但可用[\s\S]*代替

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!