xmldocument

No Nodes Selected from Atom XML document using XPath?

冷暖自知 提交于 2019-11-27 07:00:19
问题 I'm trying to parse an Atom feed programmatically. I have the atom XML downloaded as a string. I can load the XML into an XmlDocument . However, I can't traverse the document using XPath. Whenever I try, I get null . I've been using this Atom feed as a test: http://steve-yegge.blogspot.com/feeds/posts/default Calling SelectSingleNode() always returns null , except for when I use " / ". Here is what I'm trying right now: using (WebClient wc = new WebClient()) { string xml = wc.DownloadString(

Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function

天大地大妈咪最大 提交于 2019-11-27 02:07:04
问题 I am trying to call SelectNode from XmlDocument class and trouble due to this error: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function. My code: public void Add(ref XmlDocument xmlFormat, String strName) { XmlDocument dom; XSLTemplate xsl = null; String strPath = ""; XmlNodeList nl; XmlAttribute na; int n; nl = (XmlNodeList)xmlFormat.SelectNodes("//xsl:import/@href",nsm); } and xsl: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org

Data at the root level is invalid. Line 1, position 1 -why do I get this error while loading an xml file?

陌路散爱 提交于 2019-11-27 01:49:22
Data at the root level is invalid. Line 1, position 1 -why I get this error while load xml file this my code: XmlDocument xmlDoc=new XmlDocument(); xmlDoc.LoadXml("file.xml"); The LoadXml method is for loading an XML string directly. You want to use the Load method instead. 来源: https://stackoverflow.com/questions/7544475/data-at-the-root-level-is-invalid-line-1-position-1-why-do-i-get-this-error-w

How to add xmlnamespace to a xmldocument

一世执手 提交于 2019-11-26 21:47:14
问题 Im trying to create a xml the should look like this <?xml version="1.0" encoding="iso-8859-1"?> <MyTestSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Tests> <Test> <messaure>1</messaure> <height>4</height> </Test> <Test> <messaure>4</messaure> <height>53</height> </Test> </Tests> </MyTestSet> Its not a problem to create the Tests or Test elements, but what is the best way to Create the "MyTestSet" including the namespaces? Im using c#

Performance: XDocument versus XmlDocument

杀马特。学长 韩版系。学妹 提交于 2019-11-26 21:12:22
问题 I have read a comparison between the two here. This is primarily a question of performance, relating to both memory and speed. I've got several XML documents that are upwards of 100 - 300 K in size. I've noticed that there is some lag when loading this information into an XDocument rather than an XmlDocument object. Is there a serious performance difference between these two objects? Do they access the content of the XML differently? When working with a string of XML, which is preferred, or

How to get XML with header (<?xml version=“1.0”…)?

不羁的心 提交于 2019-11-26 21:09:22
问题 Consider the following simple code which creates an XML document and displays it. XmlDocument xml = new XmlDocument(); XmlElement root = xml.CreateElement("root"); xml.AppendChild(root); XmlComment comment = xml.CreateComment("Comment"); root.AppendChild(comment); textBox1.Text = xml.OuterXml; it displays, as expected: <root><!--Comment--></root> It doesn't, however, display the <?xml version="1.0" encoding="UTF-8"?> So how can I get that as well? 回答1: Create an XML-declaration using

How to remove all comment tags from XmlDocument

为君一笑 提交于 2019-11-26 21:08:50
问题 How would i go about to remove all comment tags from a XmlDocument instance? Is there a better way than retrieving a XmlNodeList and iterate over those? XmlNodeList list = xmlDoc.SelectNodes("//comment()"); foreach(XmlNode node in list) { node.ParentNode.RemoveChild(node); } 回答1: When you load the xml, you can use XmlReaderSettings XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreComments = true; XmlReader reader = XmlReader.Create("...", settings); xmlDoc.Load(reader); On

How do I get the entire XML string from a XMLDocument returned by jQuery (cross browser)?

爷,独闯天下 提交于 2019-11-26 20:31:15
问题 I have tried and failed to find out how to get the entire XML string from the XMLDocument returned by a GET. There are a lot of questions on SO on how to find or replace specific elements in the object, but I can't seem to find any answer to how to get the entire document as a string. The example I'm working with is from here. The "do something with xml"-part is where I'm at at the moment. I get the feeling that this should be really trivial, but I fail to find out how. Is there an "xml.data(

XML Document to String

风流意气都作罢 提交于 2019-11-26 19:44:22
What's the simplest way to get the String representation of a XML Document ( org.w3c.dom.Document )? That is all nodes will be on a single line. As an example, from <root> <a>trge</a> <b>156</b> </root> (this is only a tree representation, in my code it's a org.w3c.dom.Document object, so I can't treat it as a String) to "<root> <a>trge</a> <b>156</b> </root>" Thanks! Assuming doc is your instance of org.w3c.dom.Document : TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"

How to prevent blank xmlns attributes in output from .NET's XmlDocument?

戏子无情 提交于 2019-11-26 18:42:35
When generating XML from XmlDocument in .NET, a blank xmlns attribute appears the first time an element without an associated namespace is inserted; how can this be prevented? Example: XmlDocument xml = new XmlDocument(); xml.AppendChild(xml.CreateElement("root", "whatever:name-space-1.0")); xml.DocumentElement.AppendChild(xml.CreateElement("loner")); Console.WriteLine(xml.OuterXml); Output: <root xmlns="whatever:name-space-1.0"><loner xmlns="" /></root> Desired Output: <root xmlns="whatever:name-space-1.0"><loner /></root> Is there a solution applicable to the XmlDocument code, not something