xmldocument

Serialize XmlDocument & send via HTTPWebRequest

心已入冬 提交于 2020-01-11 07:11:09
问题 I'm trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object. Here's what I have thus far: Stream requestStream; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/Track"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; requestStream = request.GetRequestStream(); XmlSerializerNamespaces xsm = new XmlSerializerNamespaces(); xsm

XPath with XmlDocument not finding nodes

删除回忆录丶 提交于 2020-01-06 15:59:10
问题 so I'm having some trouble with my XPath not selecting any nodes from an XML tree. Here's my code so far: var reader = new XmlDocument(); reader.Load(@"http://www.fieldgulls.com/rss/current"); XmlNodeList list = reader.SelectNodes("./entry"); I've also tried XPath values of */entry, //entry, and others. I can't seem to get anything to work though. What am I doing wrong? 回答1: The problem is that the elements <Entry> are actually in the default namespace of the root node, which is "http://www

Low memory when using XmlDocument

旧城冷巷雨未停 提交于 2020-01-06 06:49:49
问题 I have a function that will will generate a dataset and create an xml file from it. The function is working perfectly. The problem is that I will get an "Out of memory" error after running the report several times. When I test the report I found that the memory usage will increase a lot when it reachs this XmlDocument command. I used the GC but no use, any suggestions? if (ddlDir.SelectedItem != null && ddlSec.SelectedItem != null) { using (DataSet dsClosedKPICalls = GetReportData()) {

XmlDocument class is removing formatting, c#, .NET

泄露秘密 提交于 2020-01-03 13:01:30
问题 i was wondering if anyone knows how to stop xmldocument.Save() from reformatting the document. Its not that the document is not formatted correctly with respect to XML, the particular document i am working with has lots of white space and things like that which - upon save - is all being removed. 回答1: Set the PreserveWhiteSpace property to true before you save the document. 回答2: set PreserveWhiteSpace to true 来源: https://stackoverflow.com/questions/1684253/xmldocument-class-is-removing

Strategy for parsing LOTS and LOTS of not-so-well formed SGML / XML documents

我只是一个虾纸丫 提交于 2019-12-31 03:24:06
问题 I have thousands of SGML documents, some well-formed, some not so well-formed. I need to get at certain ELEMENTS in the documents, but everytime I go to load and try to read them into an XDocument, XMLDocument, or even just a StreamReader, I get different various XMLException errors. Things like "'[' is an unexpected token.". Why? Because I have a document with DOCTYPE like <!DOCTYPE RChapter PUBLIC "-//LSC//DTD R Chapter for Authoring//EN" [] > and I have learned that the "[]" needs to have

Using XPath to parse an XML document

♀尐吖头ヾ 提交于 2019-12-30 07:59:10
问题 Lets say I have the following xml (a quick example) <rows> <row> <name>one</name> </row> <row> <name>two</name> </row> </rows> I am trying to parse this by using XmlDocument and XPath (ultimately so I can make a list of rows). For example... XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); foreach(XmlNode row in doc.SelectNodes("//row")) { string rowName = row.SelectSingleNode("//name").InnerText; } Why, within my foreach loop, is rowName always "one"? I am expecting it to be "one" on

Using XPath to parse an XML document

放肆的年华 提交于 2019-12-30 07:59:04
问题 Lets say I have the following xml (a quick example) <rows> <row> <name>one</name> </row> <row> <name>two</name> </row> </rows> I am trying to parse this by using XmlDocument and XPath (ultimately so I can make a list of rows). For example... XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); foreach(XmlNode row in doc.SelectNodes("//row")) { string rowName = row.SelectSingleNode("//name").InnerText; } Why, within my foreach loop, is rowName always "one"? I am expecting it to be "one" on

How do I add multiple namespaces to the root element with XmlDocument?

跟風遠走 提交于 2019-12-28 14:43:40
问题 I need to create an XmlDocument with a root element containing multiple namespaces. Am using C# 2.0 or 3.0 Here is my code: XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("JOBS", "http://www.example.com"); doc.AppendChild(root); XmlElement job = doc.CreateElement("JOB", "http://www.example.com"); root.AppendChild(job); XmlElement docInputs = doc.CreateElement("JOB", "DOCINPUTS", "http://www.example.com"); job.AppendChild(docInputs); XmlElement docInput = doc

How do I add multiple namespaces to the root element with XmlDocument?

与世无争的帅哥 提交于 2019-12-28 14:43:17
问题 I need to create an XmlDocument with a root element containing multiple namespaces. Am using C# 2.0 or 3.0 Here is my code: XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("JOBS", "http://www.example.com"); doc.AppendChild(root); XmlElement job = doc.CreateElement("JOB", "http://www.example.com"); root.AppendChild(job); XmlElement docInputs = doc.CreateElement("JOB", "DOCINPUTS", "http://www.example.com"); job.AppendChild(docInputs); XmlElement docInput = doc

Serialize object to XmlDocument

爱⌒轻易说出口 提交于 2019-12-28 05:30:33
问题 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