2014-03-06 247 views
0

我正在使用XmlTextWriter并从加载其他服务的URL时出现错误。错误是“路径中的非法字符”。我曾尝试使用@“https://www.foo.com/foobar/rest-1/Data/Test?sel=GeneratedFrom&find=TS-01108&findin=Parent.Number路径c#中的非法字符 - XmlTextWriter

当我使用调试器进行检查时,发现该值有引号,但我怀疑它可能是“?”,“=”,“&”或“。”。也许。

string URL = "https://www.foo.com/foobar/rest-1/Data/Test?sel=GeneratedFrom&find=TS-01108&findin=Parent.Number"; 

string XML_FILENAME = URL + ".xml"; 

     WebResponse response = utils.GetRestResponse(URL); 
     if (response != null) 
     { 
      XmlDocument xmldoc = new XmlDocument(); 
      xmldoc.Load(XmlReader.Create(response.GetResponseStream())); 

      // Illegal characters in path happens here 
      XmlTextWriter writer = new XmlTextWriter(XML_FILENAME, null); 
+0

你需要一个文件,而不是一个网址。 – Xaruth

回答

2

我想你误解了第一个XmlTextWriter初始化参数的目的。如果一个字符串参数在那里传递,那应该是一个文件名而不是一个Web资源。

+0

它使用“https://www.foo.com/foobar/rest-1/Data/Test/12345”。然后它为我提供“测试”12345或https://www.foo.com/foobar/rest-1/Data/Test的所有数据将返回所有测试的所有属性值。所以,我可以加载所有测试的xml数据,并以这种方式获取特定数据。我只是试图查看是否可以从查询中加载特定的一组数据。谢谢你澄清,这是有道理的。 –