xmldocument

Webservice method return XmlDocument, Reference sees a XmlNode

♀尐吖头ヾ 提交于 2019-12-05 18:03:46
I've faced a problem I can't solve that's why I beg you to help me! I'm working with a WebService and I'm trying to return a XmlDocument from a WebService method called GetSystemDocument which looks like : [WebMethod(Description = "blabla")] public XmlDocument GetSystemDocument(string DocumentName) { return new XmlDocument(); } In the project where I reference this web service. Visual Studio tells me it cannot implicitily convert type 'System.Xml.XmlNode' to 'System.Xml.XmlDocument'. If I look into the Reference.cs file(generated by Visual Studio) the code looks like : /// <remarks/> [System

How to use clipboard to copy data from Excel Sheet to DataTable?

旧巷老猫 提交于 2019-12-05 15:23:33
I have a Winform project, created on Microsoft Framework 3.5. The users may have installed Windows 7 or Windows XP, and Office 2007 or above. I'm working on in a procedure to get the clipboard data and put in on a C# DataTable. I already created a method to get the raw data from the clipboard and upload it in a DataTable. But in some cases, the Excel data shows a value, but internally have another: I'm investigating a method to get the raw data from Excel: string XmlFmt = "XML Spreadsheet"; var clipboard = Clipboard.GetDataObject(); if (clipboard.GetDataPresent(XmlFmt)) { var clipData =

How to save XmlDocument with multiple indentation settings?

我怕爱的太早我们不能终老 提交于 2019-12-05 10:13:19
I need to save one XmlDocument to file with proper indentation (Formatting.Indented) but some nodes with their children have to be in one line (Formatting.None) . How to achieve that since XmlTextWriter accept setting for a whole document? Edit after @Ahmad Mageed's resposne: I didn't know that XmlTextWriter settings can be modified during writing. That's good news. Right now I'm saving xmlDocument (which is already filled with nodes, to be specific it is .xaml page) this way: XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.UTF8); writer.Formatting = Formatting.Indented;

XmlDocument and slow schema processing

我与影子孤独终老i 提交于 2019-12-05 09:43:22
I have an xml template document that I need to load into an XmlDocument. eg myXMLDocument.Load(myXMLFile); However this is very slow as it loads in the dtd. I have tried both "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" and a local copy of the dtd. Both take more or less the same time. If I turn of loading the dtd by setting the resolver to null (for example), I then get errors such as "Reference to undeclared entity 'nbsp'" if the document contains these. I need to use an XmlDocument as I need to manipulate the DOM before outputting the document. How can I get round these problems? You can

How to select nodes where node name contains “mystring”

风格不统一 提交于 2019-12-05 08:30:47
I need to get XmlNodeList where node name contains "mystring" XML <?xml version="1.0" encoding="utf-8"?> <root> <node1> node1 value </node1> <node2_mystring> node2 value </node2_mystring> <node3> node3 value </node3> <node4_mystring> node 4 value </node4_mystring> </root> Desired output is <?xml version="1.0" encoding="utf-8"?> <root> <node2_mystring> node2 value </node2_mystring> <node4_mystring> node 4 value </node4_mystring> </root> I tried something like XmlNodeList mystringElements = xmlDocument.SelectNodes(@"//*[contains(name,'mystring')]"); But it returns zero node. What should I put in

How make XMLDocument do not put spaces on self-closed tags?

折月煮酒 提交于 2019-12-05 06:08:35
I have an XML well formatted without any spaces. It' must be like that. When I load it to XMLDocument to sign, the self-closing tags gets an extra white space and <cEAN/> becomes: <cEAN /> Once this document must be signed, it's impossible to remove the white space. The property PreserveWhiteSpace doesn't made any difference to the result. How can I change this behavior? There is no space before the closing "/" in the XmlDocument . XmlDocument is a data structure consisting of nodes. It is binary. It is not text. Any extra space you are seeing exists only when you serialize the document as

ASP.NET: Will Saving an XmlDocument to the Response.OutputStream honor the encoding?

徘徊边缘 提交于 2019-12-05 01:13:24
问题 i want to send the xml of an XmlDocument object to the HTTP client, but i'm concerned that the suggested soltuion might not honor the encoding that the Response has been set to use: public void ProcessRequest(HttpContext context) { XmlDocument doc = GetXmlToShow(context); context.Response.ContentType = "text/xml"; context.Response.ContentEncoding = System.Text.Encoding.UTF8; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Cache

Why does XmlDocument.LoadXml throw System.Net.WebException?

主宰稳场 提交于 2019-12-05 00:55:09
Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ? This is really mind boggling crazy, if MSDN was right, LoadXml should at most give me a System.Xml.XmlException . Yet I have weird exceptions like: The underlying connection was closed: The connection was closed unexpectedly. Dim document As New XmlDocument document.LoadXml("<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><x></x>") MsgBox(document.LastChild.Name) What on earth is causing the exception ? Edwin gave you the solution, and I'm

How can I change an attribute value of a XML file in c#?

China☆狼群 提交于 2019-12-04 17:44:45
I have a XML file(web.config) and I need to edit the value attribute of each tag, depend of the key name... this is an example of the XML file: <appSettings> <add key="A1" value="Hi" /> <add key="B1" value="Hello" /> </appSettings> I mean, How can I change the value "hi" & "hello" using the key attribute(A1 & B1) ?? Thanks alot try this code, it works fine: XmlDocument doc = new XmlDocument(); doc.Load("Your.xml"); XmlNodeList elementList = doc.GetElementsByTagName("add"); for (int i = 0; i < elementList.Count; i++) { if(elementList[i].Attributes["key"].Value == "A1") elementList[i].Attributes

Search for nodes by name in XmlDocument

僤鯓⒐⒋嵵緔 提交于 2019-12-04 16:45:31
问题 I'm trying to find a node by name in an XmlDocument with the following code: private XmlNode FindNode(XmlNodeList list, string nodeName) { if (list.Count > 0) { foreach (XmlNode node in list) { if (node.Name.Equals(nodeName)) return node; if (node.HasChildNodes) FindNode(node.ChildNodes, nodeName); } } return null; } I call the function with: FindNode(xmlDocument.ChildNodes, "somestring"); For some reason it always returns null and I'm not really sure why. Can someone help me out with this?