xmldocument

Serialize object to XmlDocument

故事扮演 提交于 2019-11-27 19:30:32
In order to return useful information in SoapException.Detail for an asmx web service, I took an idea from WCF and created a fault class to contain said useful information. That fault object is then serialised to the required XmlNode of a thrown SoapException . I'm wondering whether I have the best code to create the XmlDocument - here is my take on it: var xmlDocument = new XmlDocument(); var serializer = new XmlSerializer(typeof(T)); using (var stream = new MemoryStream()) { serializer.Serialize(stream, theObjectContainingUsefulInformation); stream.Flush(); stream.Seek(0, SeekOrigin.Begin);

C# extracting data from XML

[亡魂溺海] 提交于 2019-11-27 16:40:20
问题 I'm trying to read weather data from XML in a URL. The XML looks like this: <weatherdata> <location>...</location> <credit>...</credit> <links>...</links> <meta>...</meta> <sun rise="2013-05-11T04:49:22" set="2013-05-11T21:39:03"/> <forecast> <text>...</text> <tabular> <time from="2013-05-11T01:00:00" to="2013-05-11T06:00:00" period="0"> <!-- Valid from 2013-05-11T01:00:00 to 2013-05-11T06:00:00 --> <symbol number="2" name="Fair" var="mf/02n.03"/> <precipitation value="0" minvalue="0"

Decode CDATA section in C#

心已入冬 提交于 2019-11-27 16:15:26
问题 I have a bit of XML as follows: <section> <description> <![CDATA[ This is a "description" that I have formatted ]]> </description> </section> I'm accessing it using curXmlNode.SelectSingleNode("description").InnerText but the value returns \r\n This is a "description"\r\n that I have formatted instead of This is a "description" that I have formatted. Is there a simple way to get that sort of output from a CDATA section? Leaving the actual CDATA tag out seems to have it return the same way.

Reading XML with an “&” into C# XMLDocument Object

那年仲夏 提交于 2019-11-27 13:36:57
I have inherited a poorly written web application that seems to have errors when it tries to read in an xml document stored in the database that has an "&" in it. For example there will be a tag with the contents: "Prepaid & Charge". Is there some secret simple thing to do to have it not get an error parsing that character, or am I missing something obvious? EDIT: Are there any other characters that will cause this same type of parser error for not being well formed? The problem is that the xml is not well-formed. Properly generated xml would list that data like this: Prepaid & Charge I've had

“An object reference is required for the non-static field, method, or property”

血红的双手。 提交于 2019-11-27 08:52:38
问题 i am stuck with this small problem in my code. I am trying to make small console application which will write into xml document. I have used xmldocument and xmlnode concept. ERROR i am getting is; *An object reference is required for the non-static field, method, or property 'Write_xml.Program.give_node(System.Xml.XmlDocument)' C:\Documents and Settings\Administrator\Desktop\Write_xml\Write_xml\Program.cs* code is okay except 1 error. I am not able to resolve it ,i want somebody to check it

C# Adding data to xml file

牧云@^-^@ 提交于 2019-11-27 08:25:35
问题 I'm building an Parts app in order to learn C# and WPF. I trying having trouble adding new parts using XmlWriter. I can create the xml file, but can not figure how to add additional parts. Should I be using something else like XmlDocument? Here is my code behind: private void btnSave_Click(object sender, RoutedEventArgs e) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("f:\\MyParts

Creating an XML document using namespaces in Java

可紊 提交于 2019-11-27 07:51:56
I am looking for example Java code that can construct an XML document that uses namespaces. I cannot seem to find anything using my normal favourite tool so was hoping someone may be able to help me out. I am not sure, what you trying to do, but I use jdom for most of my xml-issues and it supports namespaces (of course). The code: Document doc = new Document(); Namespace sNS = Namespace.getNamespace("someNS", "someNamespace"); Element element = new Element("SomeElement", sNS); element.setAttribute("someKey", "someValue", Namespace.getNamespace("someONS", "someOtherNamespace")); Element

How can I stop empty XML elements self-closing using XmlDocument in C#?

假装没事ソ 提交于 2019-11-27 07:50:16
问题 Before I get jumped on by people saying the XML parser shouldn’t care if the elements are empty or self-closed, there is a reason why I can’t allow self-closed XML elements. The reason is that I’m actually working with SGML not XML and the SGML DTD I’m working with is very strict and doesn't allow it. What I have is several thousand SGML files which I’ve needed to run XSLT on. I’ve therefore had to convert the SGML to XML temporarily in order to apply the XSLT. I’ve then written a method that

How to modify existing XML file with XmlDocument and XmlNode in C#

青春壹個敷衍的年華 提交于 2019-11-27 07:47:50
I already implemented to create the XML file below with XmlTextWriter when application initialization. And know I don't know how to update the childNode id value with XmlDocument & XmlNode . Is there some property to update the id value? I tried InnerText but failed. thank you. <?xml version="1.0" encoding="UTF-8"?> <Equipment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <License licenseId="" licensePath=""/> <DataCollections> <GroupAIDs> <AID id="100"> <Variable id="200"/> <Variable id="201"/> </AID> <AID id=""> <Variable id="205"/> </AID

C# get values from xml attributes

梦想与她 提交于 2019-11-27 07:05:18
问题 How to get attribute "action" and "filename" values in a right way using C#? XML: <?xml version="1.0" encoding="utf-8" ?> <Config version="1.0.1.1" > <Items> <Item action="Create" filename="newtest.xml"/> <Item action="Update" filename="oldtest.xml"/> </Items> </Config> C#: i cannot get attribute values as well as how to get values in foreach loops? How to solve this? var doc = new XmlDocument(); doc.Load(@newFile); var element = ((XmlElement)doc.GetElementsByTagName("Config/Items/Item")[0]);