繁体   English   中英

选择 XML 的 InnerText 正在解码 URL

[英]Select InnerText of XML is decoding URL

我的问题是,当从 xml 文件(在我的情况下是数据包)中选择一个节点时,正在解码一个 url,该 url 是 xml 中节点的内部文本。 例子

<url>"http://my.xml.org/?id=AAA%2DDDD%3dNNNLKLKJLKL%2"</url>

使用 XmlDocument 的一个实例:

xmlDoc.SelectSingleNode("url").InnerText;

返回的字符串是: "http://my.xml.org/?id=AAA/DDDD/NNNLKLKJLKL/"

我如何防止这种情况发生? 请注意,%2 和 %3 已更改为正斜杠。

下面的代码得到正确的结果。 你在做什么不同?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string xml =
                "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
                "<url>\"http://my.xml.org/?id=AAA%2DDDD%3dNNNLKLKJLKL%2\"</url>";

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);
            string results = xmlDoc.SelectSingleNode("url").InnerText;

        }
    }
}
​

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM