Tag: linq to xml

将XDocument转换为Stream

如何将XDocument中的XML转换为MemoryStream,而不保存任何内容到磁盘?

我如何使XElement的价值被包裹!]?

这是从.net使用XDocument。 我认为这可能工作… xElement.Element(elementName).Value = new XCData(value).ToString(); 但它是这样出来的 <name>&lt;![CDATA[hello world]]&gt;</name>

在XDocument中查找元素?

我有一个简单的XML <AllBands> <Band> <Beatles ID="1234" started="1962">greatest Band<![CDATA[lalala]]></Beatles> <Last>1</Last> <Salary>2</Salary> </Band> <Band> <Doors ID="222" started="1968">regular Band<![CDATA[lalala]]></Doors> <Last>1</Last> <Salary>2</Salary> </Band> </AllBands> 但是, 当我想要达到“门带”并更改其ID: using (var stream = new StringReader(result)) { XDocument xmlFile = XDocument.Load(stream); var query = from c in xmlFile.Elements("Band") select c; … query 没有结果 但 如果我写xmlFile.Elements().Elements("Band")所以它find它。 问题是什么 ? 根需要完整的path吗? 如果是这样,为什么它没有指定AllBands ? XDocument导航是否要求我知道完整级别的结构到所需的元素?

linq问题:查询嵌套集合

我有一个问题类具有公共列表属性,可以包含几个答案 。 我有一个问题库,它负责从XML文件中读取问题及其答案。 所以我有一个问题(列表)的集合与每个问题对象有一个答案的集合,我想查询这个问题的答案(即通过其名称)使用Linq的集合。 我不知道如何正确地做到这一点。 我可以用foreach做,但是我想知道是否有一种纯粹的Linq方法,因为我正在学习它。

理解Linq到Xml – 后代没有返回结果

我完全是Linq2XML的新手,因为我编写了很多行来执行简单的事情,在一个简单的项目中,我想尝试一下… 我与这个2小时,没有什么我得到它的权利:( 我真的很想回到XmlNode-code-like 任务: 我发送一个SOAP Action到一个ASMX服务,我得到的答复是XML 我把XMLparsing成一个XDocument对象 我尝试获取节点列表…错误! 问题! 正如你可以从这个截图看到的 替代文字http://www.balexandre.com/temp/2010-02-26_0038.png 我的XDocument有一个名为TransactionInformationType的节点,它是一个序列,我简单地想要得到所有的,并检索我需要的只有2个variables(你可以看到代码注释) 在Watch窗口中可以看到 doc.Descendants("TransactionInformationType") 什么也没有返回,并且通过Text Visualizer中的XDocument的内容来看,它确实存在! 任何人都在意解释和帮助我通过这个巨大的墙? 谢谢! 添加 XDocument内容 回答 响应XML有 <gettransactionlistResponse xmlns="https://ssl.ditonlinebetalingssystem.dk/remote/payment"> 我必须使用这个作为命名空间! 结果是,为了检索值 ,我也需要使用XNamespace ,所以最终的代码如下所示: // Parse XML XDocument doc = XDocument.Parse(strResponse); XNamespace ns = "https://ssl.ditonlinebetalingssystem.dk/remote/payment"; var trans = from item in doc.Descendants(ns + "TransactionInformationType") select new TransactionInformationType { capturedamount = Convert.ToInt32(item.Element(ns […]

如何从Xdocument获取Xml作为string

我是linq to XML的新手。 在构buildXDocument之后,如何像使用XmlDocument一样获取它的OuterXml。

如何用LINQ-to-XMLselect一个特定的节点

我可以select第一个客户节点,并使用下面的代码更改公司名称。 但是,如何selectID = 2的客户节点呢? XDocument xmldoc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("These are all the customers transfered from the database."), new XElement("Customers", new XElement("Customer", new XAttribute("ID", 1), new XElement("FullName", "Jim Tester"), new XElement("Title", "Developer"), new XElement("Company", "Apple Inc.") ), new XElement("Customer", new XAttribute("ID", 2), new XElement("FullName", "John Testly"), new XElement("Title", "Tester"), new […]

如何在LINQ to XML中做一个元素的深层副本?

我想做一个LINQ to XML XElement的深层副本。 我想这样做的原因是文档中有一些节点需要创build(在同一文档中)的修改副本。 我没有看到一个方法来做到这一点。 我可以将元素转换为XMLstring,然后重新parsing它,但是我想知道是否有更好的方法。

如何使用XDocument打印<?xml version =“1.0”?>

使用ToString方法时,有没有办法让XDocument打印xml版本? 有它输出这样的东西: <?xml version="1.0"?> <!DOCTYPE ELMResponse [ ]> <Response> <Error> … 我有以下几点: var xdoc = new XDocument(new XDocumentType("Response", null, null, "\n"), … 这将打印这很好,但它缺less上面所述的“<?xml版本”。 <!DOCTYPE ELMResponse [ ]> <Response> <Error> … 我知道你可以通过手动输出我自己做到这一点。 只是想知道是否可以通过使用XDocument。

XElement的孩子

我怎样才能得到XElement的孩子? 我目前正在使用XElement.Descendants()函数,它返回所有级别的XElements,而不仅仅是子节点。 我真正喜欢的是一个IEnumerable只是孩子。