xmldocument

XmlDocument and slow schema processing

╄→гoц情女王★ 提交于 2019-12-22 06:40:37
问题 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

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

此生再无相见时 提交于 2019-12-22 05:08:14
问题 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? 回答1: There is no space before the closing "/" in the XmlDocument . XmlDocument is a data structure consisting of nodes. It

Looping through XML document

点点圈 提交于 2019-12-22 04:22:29
问题 My XML file structure looks like this: <SalaryDetails> <Employee> <Name>George Dsouza</Name> <AnnualSalary>320000</AnnualSalary> <DaysWorked>22</DaysWorked> </Employee> <Employee> <Name>Jackie Parera</Name> <AnnualSalary>300000</AnnualSalary> <DaysWorked>19</DaysWorked> </Employee> ... </SalaryDetails> I want to put all the data into database as employe records using XmlDocument . So I wrote a loop like this: XmlDocument xdcDocument = new XmlDocument(); xdcDocument.Load(@"D:\SalaryDetails.xml

ImportNode creates empty xmlns attribute

早过忘川 提交于 2019-12-21 08:55:33
问题 Regrading this code: var tmpNewNode = xdoc.ImportNode(newNode, true); if (oldNode.ParentNode != null) { oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode); return true; } tmpNewNode is created with empty xmlns attribute (xmlns=""). Any suggestion how can I avoid it? 10x 回答1: What's probably happening here is that newNode comes from a document with no namespace declared, but oldNode is in a document with a namespace. In this situation, the node takes its blank namespace over to the new

ImportNode creates empty xmlns attribute

≡放荡痞女 提交于 2019-12-21 08:54:42
问题 Regrading this code: var tmpNewNode = xdoc.ImportNode(newNode, true); if (oldNode.ParentNode != null) { oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode); return true; } tmpNewNode is created with empty xmlns attribute (xmlns=""). Any suggestion how can I avoid it? 10x 回答1: What's probably happening here is that newNode comes from a document with no namespace declared, but oldNode is in a document with a namespace. In this situation, the node takes its blank namespace over to the new

Split XML document apart creating multiple output files from repeating elements

你说的曾经没有我的故事 提交于 2019-12-21 05:30:26
问题 I need to take an XML file and create multiple output xml files from the repeating nodes of the input file. The source file "AnimalBatch.xml" looks like this: <?xml version="1.0" encoding="utf-8" ?> <Animals> <Animal id="1001"> <Quantity>One</Quantity> <Adjective>Red</Adjective> <Name>Rooster</Name> </Animal> <Animal id="1002"> <Quantity>Two</Quantity> <Adjective>Stubborn</Adjective> <Name>Donkeys</Name> </Animal> <Animal id="1003"> <Quantity>Three</Quantity> <Color>Blind</Color> <Name>Mice<

Which is the best for performance wise: XPathNavigator with XPath vs Linq to Xml with query?

有些话、适合烂在心里 提交于 2019-12-21 05:24:05
问题 I have an application in which I am using XPathNavigator to iterate nodes. It is working fine. But I want to know that if I use LINQ to Xml.... What benefits(Performance, maintainability) I will get? With XPath, LINQ to Xml what is the performance hit? I am using C#.net, VS 2010 and my .xml is mid size. 回答1: Well, XPathNavigator will generally be faster than Linq to XML queries. But there's always 'but'. Linq to XML will definitely make your code more readable and maintainable. It's easier

How to update XML nodes with new values?

亡梦爱人 提交于 2019-12-21 05:17:04
问题 I have a xml inside my App_Data folder. I need to edit the values in nodes of that xml. What I had tried is- XmlDocument xDoc = new XmlDocument(); xDoc.Load(Server.MapPath("~/App_Data/conf.xml.config")); XmlNodeList aNodes = xDoc.SelectNodes("/ConfigInf"); foreach (XmlNode node in aNodes) { XmlNode child1 = node.SelectSingleNode("Node1"); XmlNode child2 = node.SelectSingleNode("Node2"); child1.InnerText = "Value1"; child2.InnerText = "Value2"; } I need to re-write the xml with new values as

Returning XmlDocument from WCF service not working

天大地大妈咪最大 提交于 2019-12-20 06:17:05
问题 I am trying to update some WCF service methods that return strings to return XmlDocument objects. I've tried returning it as-is and encapsulating it in a datacontract object. Either way I'm hitting an error upon attempting to update the service reference. The error suggest encapsulating it in a datacontract with an operations contract which I am doing. Is there a trick to this? 回答1: There's a way to return a XmlDocument from WCF, but you need to use the XmlSerializer instead of the default

SelectSingleNode returns null even with namespace managing

亡梦爱人 提交于 2019-12-20 04:32:22
问题 I've come from this question, where my first issue was solved: XML Select a single node where the names are repeating It was a namespace issue first. But now even with the corect NameSpace managing my XPath still returns me null. I've also checked: SelectSingleNode return null - even with namespace SelectSingleNode always returns null? XmlDocument.SelectSingleNode and xmlNamespace issue SelectSingleNode returning null for known good xml node path using XPath Why is SelectSingleNode returning