xmldocument

XMLdocument Sort

谁都会走 提交于 2019-12-01 09:37:46
问题 I've figured out how to append nodes to my rss document in the right structyre. I now need to sort it in the pubDate order and then output to screen. Looking at the examples online, I've found lots of XDocument and Linq stuff but nothing with XmlDocument. Scratching my head whether to scrap what code I have and work out how to do it in XDocument with advice from here or continue with XMLDocument and figure out a way to sort. With XMLDocument I've got the code working exactly as I want, just

Serialize XmlDocument & send via HTTPWebRequest

删除回忆录丶 提交于 2019-12-01 09:37:16
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.Add("", ""); // remove namespace XmlSerializer ser = new XmlSerializer(xmlRequest.GetType()); ser

Invalid character in the given encoding

瘦欲@ 提交于 2019-12-01 09:26:02
问题 XmlDocument oXmlDoc = new XmlDocument(); try { oXmlDoc.Load(filePath); } catch (Exception ex) { // Log Error Here try { Encoding enc = Encoding.GetEncoding("iso-8859-1"); StreamReader sr = new StreamReader(filePath, enc); String response = sr.ReadToEnd(); oXmlDoc.LoadXml(response); } catch (Exception innerException) { // Log Error Here return false; } } I got xml file from third party which also include the Document Type Definition file after xml declaration. <?xml version="1.0" encoding="UTF

XSLT transformation in memory using C#

送分小仙女□ 提交于 2019-12-01 08:51:19
Good afternoon all, I dont know why this is proving so difficult but I must be having one of those days! I am trying to perform and XslCompiledTransform on an in memory XmlDocument (I have retrieved the XML from a webservice and saved to a database) object. I have the following code so far: string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt"; XslCompiledTransform processor = new XslCompiledTransform(); processor.Load(xslFile); MemoryStream ms = new MemoryStream(); processor.Transform(xdoc.CreateNavigator(), null, ms); ms.Seek(0, SeekOrigin.Begin); StreamReader reader = new

XSLT transformation in memory using C#

感情迁移 提交于 2019-12-01 07:02:22
问题 Good afternoon all, I dont know why this is proving so difficult but I must be having one of those days! I am trying to perform and XslCompiledTransform on an in memory XmlDocument (I have retrieved the XML from a webservice and saved to a database) object. I have the following code so far: string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt"; XslCompiledTransform processor = new XslCompiledTransform(); processor.Load(xslFile); MemoryStream ms = new MemoryStream(); processor

Using XmlDocument to Retrieve values in c#

ぃ、小莉子 提交于 2019-12-01 06:16:44
I am using XmlDocument() for parsing a file like **.opf ** for my application of EpubReader. <item id="W01MB154" href="01MB154.html" media-type="application/xhtml+xml" /> <item id="W000Title" href="000Title.html" media-type="application/xhtml+xml" /> with <itemref idref="W000Title" /> <itemref idref="W01MB154" /> These values in same file. Here I know the value of id within the tag of item , after that I want to know the value of the href element. What I have to do is compare the value idref element in the itemref tag with element value of id in the tag item . Here I know the id value which is

Get a specific number of results from an XmlDocument XPath query

狂风中的少年 提交于 2019-12-01 05:56:02
I'm querying a Twitter RSS feed and supplying the results into a Repeater for display. I'd like to only get the first 5 results of the XPath query. Is there a way to do that in the XPath syntax or do I have to loop over the resulting XmlNodeList to pull out the first 5? XmlDocument doc = new XmlDocument(); XmlTextReader reader = new XmlTextReader(rssPath); doc.Load(reader); XmlNodeList items = doc.SelectNodes("/rss/channel/item"); rptTwitter.ItemDataBound += new RepeaterItemEventHandler(rptTwitter_ItemDataBound); rptTwitter.DataSource = items; rptTwitter.DataBind(); Try this XPath query

C# : the close method of Xml.Load(file)

北城以北 提交于 2019-12-01 05:21:38
I have written some code that loads an XML document using an XmlDocument object so as to count it's nodes. Here is the method: XmlDocument xml = new XmlDocument(); xml.Load(textBox1.Text); XmlNodeList nodes = xml.SelectNodes("//File"); foreach (XmlNode node in nodes) { number_of_childs++; } The problem that I am facing is, when importing a large file, it takes like 700MB of RAM. If I then try to do some operation on the file, or even read from it to display its data in a ListView , the application takes like 2GB of RAM. So, I was wondering, is there a method that closes the XmlDocument and

Using XmlDocument to Retrieve values in c#

独自空忆成欢 提交于 2019-12-01 04:48:16
问题 I am using XmlDocument() for parsing a file like **.opf ** for my application of EpubReader. <item id="W01MB154" href="01MB154.html" media-type="application/xhtml+xml" /> <item id="W000Title" href="000Title.html" media-type="application/xhtml+xml" /> with <itemref idref="W000Title" /> <itemref idref="W01MB154" /> These values in same file. Here I know the value of id within the tag of item , after that I want to know the value of the href element. What I have to do is compare the value idref

Is XMLDocument.Save an atomic operation?

微笑、不失礼 提交于 2019-12-01 04:37:55
Is there anyway another process monitoring for files created using XMLDocument.Save() could encounter a partial file? Does it make any difference if Save() is overwriting an existing file? If you save like this you shouldn't have any problems. using (var file = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { xmlDoc.Save(file); } I don't think that there is any guarantee of atomicity. You should not depend on it. Writing files is, in general, not atomic. Check out Process Monitor to get an idea what the OS exposes. XmlDocument.Save(string) uses FileShare