它是HtmlAgilityPack错误还是它应该以这种方式运行?

时间:2013-12-27 14:48:08

标签: c# html html-agility-pack

我想修改节点的InnerHtml属性。在我分配时,似乎有些内容会添加到属性中。即使我只获取属性值并将相同的确切值返回给属性,它也会被修改。这是一个错误吗?

例如

 string content = node.InnerHtml;
 node.InnerHtml = content;
 content = node.InnerHtml;

分配前内容的价值:

  (function(){
  var splitByFirstChar = function(toBeSplit, splitChar) {
  var index = toBeSplit.indexOf(splitChar);
  if (index >= 0) {
  return [toBeSplit.substring(0, index),
  toBeSplit.substring(index + 1)];
  }
  return [toBeSplit];
  }
  var langChooser_parseParams = function(paramsSection) {
  if (paramsSection) {
  var query = {};
  var params = paramsSection.split('&');
  for (var i = 0; i < params.length; i++) {
          var param = splitByFirstChar(params[i], '=');
          if (param.length == 2) {
            query[param[0]] = param[1];
          }
        }
        return query;
      }
      return {};
    }
    var langChooser_getParamStr = function(params) {
      var paramsStr = [];
      for (var a in params) {
        paramsStr.push(a + "=" + params[a]);
      }
      return paramsStr.join('&');
    }
    var langChooser_currentUrl = window.location.href;
    var match = langChooser_currentUrl.match("^(.*?)(\\?(.*?))?(#(.*))?$");
    var langChooser_currentPath = match[1];
    var langChooser_params = langChooser_parseParams(match[3]);
    var langChooser_fragment = match[5];

    var langChooser = document.getElementById('lang-chooser');
    var langChooserWrap = document.getElementById('lang-chooser-wrap');
    var langVisControl = document.getElementById('lang-vis-control');
    if (langVisControl && langChooser) {
      langVisControl.style.display = 'inline';
      langChooser.onchange = function() {
        langChooser_params['lp'] = 1;
        langChooser_params['hl'] = encodeURIComponent(this.value);
        var paramsStr = langChooser_getParamStr(langChooser_params);
        var newHref = langChooser_currentPath + "?" + paramsStr;
        if (langChooser_fragment) {
          newHref = newHref + "#" + langChooser_fragment;
        }
        window.location.href = newHref;
      };
    }
  })();
分配后的

内容:

  (function(){
  var splitByFirstChar = function(toBeSplit, splitChar) {
  var index = toBeSplit.indexOf(splitChar);
  if (index >= 0) {
  return [toBeSplit.substring(0, index),
  toBeSplit.substring(index + 1)];
  }
  return [toBeSplit];
  }
  var langChooser_parseParams = function(paramsSection) {
  if (paramsSection) {
  var query = {};
  var params = paramsSection.split('&');
  for (var i = 0; i < params.length; i++) {
          var param = splitbyfirstchar(params[i], '=');
          if (param.length == 2) {
            query[param[0]] = param[1];
          }
        }
        return query;
      }
      return {};
    }
    var langchooser_getparamstr = function(params) {
      var paramsstr = [];
      for (var a in params) {
        paramsstr.push(a + \"=\" + params[a]);
      }
      return paramsstr.join('&');
    }
    var langchooser_currenturl = window.location.href;
    var match = langchooser_currenturl.match(\"^(.*?)(\\\\?(.*?))?(#(.*))?$\");
    var langchooser_currentpath = match[1];
    var langchooser_params = langchooser_parseparams(match[3]);
    var langchooser_fragment = match[5];

    var langchooser = document.getelementbyid('lang-chooser');
    var langchooserwrap = document.getelementbyid('lang-chooser-wrap');
    var langviscontrol = document.getelementbyid('lang-vis-control');
    if (langviscontrol && langchooser) {
      langviscontrol.style.display = 'inline';
      langchooser.onchange = function() {
        langchooser_params['lp'] = 1;
        langchooser_params['hl'] = encodeuricomponent(this.value);
        var paramsstr = langchooser_getparamstr(langchooser_params);
        var newhref = langchooser_currentpath + \"?\" + paramsstr;
        if (langchooser_fragment) {
          newhref = newhref + \"#\" + langchooser_fragment;
        }
        window.location.href = newhref;
      };
    }
  })();
 params.length;=\"\" i++)=\"\" {=\"\" var=\"\" param=\"splitByFirstChar(params[i],\" '=');
          if (param.length == 2) {
            query[param[0]] = param[1];
          }
        }
        return query;
      }
      return {};
    }
    var langChooser_getParamStr = function(params) {
      var paramsStr = [];
      for (var a in params) {
        paramsStr.push(a + \"=\" + params[a]);
      }
      return paramsStr.join(' &');=\"\" }=\"\" var=\"\" langchooser_currenturl=\"window.location.href;\" var=\"\" match=\"langChooser_currentUrl.match(\"^(.*?)(\\\\?(.*?))?(#(.*))?$\");\" var=\"\" langchooser_currentpath=\"match[1];\" var=\"\" langchooser_params=\"langChooser_parseParams(match[3]);\" var=\"\" langchooser_fragment=\"match[5];\" var=\"\" langchooser=\"document.getElementById('lang-chooser');\" var=\"\" langchooserwrap=\"document.getElementById('lang-chooser-wrap');\" var=\"\" langviscontrol=\"document.getElementById('lang-vis-control');\" if=\"\" (langviscontrol=\"\" &&=\"\" langchooser)=\"\" {=\"\" langviscontrol.style.display='inline' ;=\"\" langchooser.onchange=\"function()\" {=\"\" langchooser_params['lp']=\"1;\" langchooser_params['hl']=\"encodeURIComponent(this.value);\" var=\"\" paramsstr=\"langChooser_getParamStr(langChooser_params);\" var=\"\" newhref=\"langChooser_currentPath\" +=\"\" \"?\"=\"\" +=\"\" paramsstr;=\"\" if=\"\" (langchooser_fragment)=\"\" {=\"\" newhref=\"newHref\" +=\"\" \"#\"=\"\" +=\"\" langchooser_fragment;=\"\" }=\"\" window.location.href=\"newHref;\" };=\"\" }=\"\" })();=\"\"></ params.length; i++) {
          var param = splitbyfirstchar(params[i], '=');
          if (param.length == 2) {
            query[param[0]] = param[1];
          }
        }
        return query;
      }
      return {};
    }
    var langchooser_getparamstr = function(params) {
      var paramsstr = [];
      for (var a in params) {
        paramsstr.push(a + \"=\" + params[a]);
      }
      return paramsstr.join('&');
    }
    var langchooser_currenturl = window.location.href;
    var match = langchooser_currenturl.match(\"^(.*?)(\\\\?(.*?))?(#(.*))?$\");
    var langchooser_currentpath = match[1];
    var langchooser_params = langchooser_parseparams(match[3]);
    var langchooser_fragment = match[5];

    var langchooser = document.getelementbyid('lang-chooser');
    var langchooserwrap = document.getelementbyid('lang-chooser-wrap');
    var langviscontrol = document.getelementbyid('lang-vis-control');
    if (langviscontrol && langchooser) {
      langviscontrol.style.display = 'inline';
      langchooser.onchange = function() {
        langchooser_params['lp'] = 1;
        langchooser_params['hl'] = encodeuricomponent(this.value);
        var paramsstr = langchooser_getparamstr(langchooser_params);
        var newhref = langchooser_currentpath + \"?\" + paramsstr;
        if (langchooser_fragment) {
          newhref = newhref + \"#\" + langchooser_fragment;
        }
        window.location.href = newhref;
      };
    }
  })();
>

1 个答案:

答案 0 :(得分:0)

解决:

HtmlNode尝试在分配内部节点时解析该值。

溶液:

                string content = node.InnerHtml;
                node.RemoveAllChildren();
                node.AppendChild(doc.CreateTextNode(content));