现在,我意识到此前提出过这类问题(特别是这个 - 我认为这是对两个对象的非常好的描述).我的问题更多是围绕表现.我有几个XML文档,大小超过100 - 300 K. 我注意到将这些信息加载到一个XDocument而不是一个XmlDocument对象时会有一些延迟.这两个对象之间是否存在严重的性能差异?他们是否以不同方式访问XML的内容?使用XML字符串时,这是首选的,或者是有区别的.这些对象的最终用途是XPath在有问题的对象上运行查询(或LINQ,取决于).
同样,这主要是性能问题,涉及内存和速度.
我能够在.NET中解析XML.现在我至少可以选择XmlTextReader和XDocument.这两者(或框架中包含的任何其他XML解析器)之间是否有任何比较?
也许这可以帮助我做出决定而不必深入尝试它们.
与易于使用相比,XML文件预计相当小,速度和内存使用是一个小问题.:-)
(我将从C#和/或IronPython中使用它们.)
谢谢!
当您创建新的XDocument使用时XDocument.Load,它是打开XML文件并保留本地副本,还是连续从硬盘驱动器读取文档?如果它连续读取,是否有更快的方法来解析XML?
XDocument x = XDocument.Load("file.xml");
Run Code Online (Sandbox Code Playgroud) 我们如何将XML文件写入字符串变量?这是我的代码,变量内容应该返回一个XML字符串:
public string GetValues2()
{
string content = "";
XmlTextWriter textWriter = new XmlTextWriter(content, null);
textWriter.WriteStartElement("Student");
textWriter.WriteStartElement("r", "RECORD", "urn:record");
textWriter.WriteStartElement("Name", "");
textWriter.WriteString("Student");
textWriter.WriteEndElement();
textWriter.Close();
return contents;
}
Run Code Online (Sandbox Code Playgroud) 我在SQL中有一个表,其中一个列是XML数据类型.我如何才能从SQL到ASP.NET(C#)代码隐藏中获得它的价值?我想将它存储为Xml类型而不是字符串类型,因为我需要操作它内部的值和属性.我试着把它放在一个字符串类型的变量上,我得到的是这样的:AAYYYNYNYNStarLight.我想要得到这个:
<ANSWERS>
<Answer item="ddl_3">A</Answer>
<Answer item="ddl_8">A</Answer>
<Answer item="ddl_13">Y</Answer>
<Answer item="ddl_16">Y</Answer>
<Answer item="ddl_19">Y</Answer>
<Answer item="ddl_22">N</Answer>
<Answer item="ddl_26">Y</Answer>
<Answer item="ddl_30">N</Answer>
<Answer item="ddl_34">Y</Answer>
<Answer item="ddl_38">N</Answer>
<Answer item="ddl_42">StarLight</Answer>
</ANSWERS>
Run Code Online (Sandbox Code Playgroud)
我该怎么做并且能够操纵每个节点?我是一个关于XML的完整菜鸟,任何帮助都会得到很大的帮助.:)
编辑:清理xml
我有个问题
我的XML文件在这里;
<altinkaynak>
<DOVIZ>
<ADI>Tarih</ADI>
<ALIS>24.07.2013 18:59:45</ALIS>
<SATIS/>
</DOVIZ>
<DOVIZ>
<ADI>USD</ADI>
<ALIS>1.9120</ALIS>
<SATIS>1.9220</SATIS>
</DOVIZ>
<DOVIZ>
<ADI>EUR</ADI>
<ALIS>2.5280</ALIS>
<SATIS>2.5430</SATIS>
</DOVIZ>
</altinkaynak>
Run Code Online (Sandbox Code Playgroud)
我如何解析这个XML文件
我编码的方式,但我得到一个解析错误信息;
if (tip == DövizKuruTipi2.Al??)
Line 44: return Decimal.Parse(doc.SelectNodes("//ALTINKAYNAK/DOVIZ/ADI=" + dovizKuru2 + "/ALIS")[0].InnerText.Replace('.', ','));
Run Code Online (Sandbox Code Playgroud)
表达式必须求值为节点集
使用XmlDocument解析XML文件有什么选择,并且以后仍然保留错误消息的行信息?(顺便说一句,是否可以使用XML Deserialisation做同样的事情?)
选项似乎包括:
我正在编写一个代码生成工具,它将接收从Visual Studio的数据集生成器生成的XSD文件,并为每个表中的每个列创建一个自定义类.我已经了解如何实现IVsSingleFileGenerator代码生成以及如何将单个文件生成器转换为多文件生成器.然而,似乎我最麻烦的一步是应该是最简单的一步.我以前从未真正使用过XML或XML-Schema,我也不知道迭代XSD文件并读出列名和类型的正确方法是什么,因此我可以构建我的代码.
有关如何读取XSD文件的教程的任何建议?如何拉也分别任何建议xs:element表示列出来,并阅读其msprop:Generator_UserColumnName,type以及msprop:Generator_ColumnPropNameInTable从每一个元素属性.
我正在尝试做一些应该很简单的事情,但我遇到了可怕的麻烦。我在 StackOverflow 中尝试了多个类似问题的代码,但无济于事。我试图从澳大利亚政府的 ABN 查询中获取各种信息。这是匿名返回 XML 值:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ABRSearchByABNResponse xmlns="http://abr.business.gov.au/ABRXMLSearch/">
<ABRPayloadSearchResults>
<request>
<identifierSearchRequest>
<authenticationGUID>00000000-0000-0000-0000-000000000000</authenticationGUID>
<identifierType>ABN</identifierType>
<identifierValue>00 000 000 000</identifierValue>
<history>N</history>
</identifierSearchRequest>
</request>
<response>
<usageStatement>The Registrar of the ABR monitors the quality of the information available on this website and updates the information regularly. However, neither the Registrar of the ABR nor the Commonwealth guarantee that the information available through this service (including search results) is accurate, up to date, complete or accept any …Run Code Online (Sandbox Code Playgroud) 给出以下 XML 示例
<aaa>
<bbb id="1">
<ccc att="123"/>
<ccc att="456"/>
<ccc att="789"/>
</bbb>
<bbb id="2">
<ccc att="321"/>
<ccc att="654"/>
<ccc att="987"/>
</bbb>
</aaa>
Run Code Online (Sandbox Code Playgroud)
作为一个名为 的 XmlDocument 对象,由于其 ID 和 XPath 指令,xDoc1我设法删除了第一个节点,将第二个节点单独保留在其中。bbbbbbaaa
但现在我想在单个字符串中获取这个已删除的节点及其标记,因为InnerText该节点的值等于
<ccc att="123"/><ccc att="456"/><ccc att="789"/>
Run Code Online (Sandbox Code Playgroud)
但我希望我的字符串等于
<bbb id='1'><ccc att="123"/><ccc att="456"/><ccc att="789"/></bbb>
Run Code Online (Sandbox Code Playgroud)
我怎样才能这样做呢?使用 XmlDocument 是强制性的。
我尝试使用该ParentNode方法,但随后它包含了另一个bbb节点。
我目前的 C# 代码:
xDoc1 = new XmlDocument();
xDoc1.Load("file.xml"); // Containing the given example above.
XmlNodeList nodes = xDoc1.SelectSingleNodes("//bbb[@id='1']");
foreach (XmlNode n in nodes) …Run Code Online (Sandbox Code Playgroud) xml ×10
c# ×9
.net ×3
linq-to-xml ×3
xpath ×3
xmldocument ×2
asp.net ×1
parsing ×1
performance ×1
xsd ×1