linq-to-xml

C# LINQ XML Query

谁都会走 提交于 2019-12-25 07:17:14
问题 I am brand new to working with LINQ. For whatever reason, I am having a very hard time digesting it. The XML document I have seems to be pretty simple, but I am not finding any pages that are helping me. I need to extract the AttributeValue field from each. (Not as a for each, but discreetly and store in a dedicated var for each AttributeId.) This is the XML: <?xml version="1.0" encoding="UTF-8"?> <Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os"> <Subject SubjectCategory="urn

C# LINQ XML Query

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:16:01
问题 I am brand new to working with LINQ. For whatever reason, I am having a very hard time digesting it. The XML document I have seems to be pretty simple, but I am not finding any pages that are helping me. I need to extract the AttributeValue field from each. (Not as a for each, but discreetly and store in a dedicated var for each AttributeId.) This is the XML: <?xml version="1.0" encoding="UTF-8"?> <Request xmlns="urn:oasis:names:tc:xacml:2.0:context:schema:os"> <Subject SubjectCategory="urn

c# LINQ to XML null value exception

房东的猫 提交于 2019-12-25 06:47:57
问题 This is my code: List<Customer> customersList = ( from e in XDocument.Load(file).Root.Elements("cust") select new Customer { CustomerID = (int)e.Element("custid"), FirstName = (string)e.Element("fname"), LastName = (string)e.Element("lname"), ShowsNumber = (int)e.Element("count_noshow"), VisitNumber = (int)e.Element("count_resos"), Cancellation = (int)e.Element("count_cancel"), }).ToList(); I got {"Value cannot be null.\r\nParameter name: element"} exception on the customerList = (....) part

Extracting data from a complex XML with LINQ

萝らか妹 提交于 2019-12-25 06:25:55
问题 My goal is to save the data contained in the ValueReference node, TimeInstant attribute, and timePosition node into variables. I am able to get the value of the valueReference node (the un-commented section works), but not the other two. Any help would be greatly appreciated. Here is the code that I am working on: public void LinqToXml() { XNamespace sosNamespace = XNamespace.Get("http://www.opengis.net/sos/2.0"); XNamespace fesNamespace = XNamespace.Get("http://www.opengis.net/fes/2.0");

Linq to XML query not picking up any values

隐身守侯 提交于 2019-12-25 05:17:06
问题 I have an XML document that I'm trying to search through. The Main structure is as follows: <?xml version="1.0"?> <!DOCTYPE ONIXMessage SYSTEM "http://www.editeur.org/onix/2.1/reference/onix-international.dtd"> <ONIXMessage xmlns="http://www.editeur.org/onix/2.1/reference" release="2.1"> <Header> <FromCompany>MyCo</FromCompany> <FromPerson>Joe Bloggs</FromPerson> <FromEmail>joe@bloggs.com</FromEmail> <SentDate>20120522</SentDate> </Header> <Product> <ProductForm>DG</ProductForm> <Title>

Extracting Data from XML to List<>

一笑奈何 提交于 2019-12-25 03:44:24
问题 I have this XML file: <?xml version="1.0" encoding="utf-8" ?> <Record> <File name="1.mot"> <Line address="040004" data="0720" /> <Line address="040037" data="31" /> <Line address="04004C" data="55AA55AA" /> </File> <File name="2.mot"> <Line address="00008242" data="06" /> <Line address="00008025" data="AFC8" /> <Line address="00009302" data="476F6C64" /> </File> </Record> What I want to do is to extract the information from the XML and convert that to list. Although I kind of don't know where

Insert new XML node using LINQ

徘徊边缘 提交于 2019-12-25 03:44:23
问题 XML: 1 aaa 2 bbb Code var doc = XDocument.Load (Server.MapPath(".") + "\\Questions.config"); var elements = from element in doc.Descendants("Question") select new { Id = element.Element("Id").Value, Text = element.Element("Text").Value, Reserver = element.Element("Reserver") != null }; StringBuilder builder = new StringBuilder(); foreach (var question in elements) { builder.AppendLine(question.Id + "-" + question.Text); } myTextBox.Text = builder.ToString(); how insert new Node 'Question' to

LINQ to XML query help needed

本秂侑毒 提交于 2019-12-25 01:43:10
问题 I have the following XML structure... <Fields> <Field> <Company>My Company</Company> </Field> <Field> <Address2>Villa at beach</Address2> </Field> <Field> <Email2>email2@mail.com</Email2> </Field> <Field> <Mobile>333-888</Mobile> </Field> <Field> <ContactMethod>Facebook</ContactMethod> </Field> </Fields> I would like to know how to get the element's name using LINQ? Something like this: var fields = (from field in contact.XmlFields.Descendants("Field") select new ContactXmlView {Field = ...

How to load XML with special characters using XDocument.Load

自作多情 提交于 2019-12-25 01:33:28
问题 **This is for silverlight application. I have a stream with xml data, which after loading massage the data and generate final file. I start by load using XDocument.Load(stream). One of the file was failing to load and after some research I foung out that one of the element has a value of 'First & Second' and load fails on hitting &. Is it possible to load XML with special characters? ( I am sure the answer is no, but worth asking). Is it possible to preprocess the XML (without performance hit

import data from xml into database

送分小仙女□ 提交于 2019-12-25 01:09:39
问题 i would like to import data into my database through an xml file: var doc = XDocument.Load(XMLFile); var nodes = from e in doc.Descendants("Person") where e.Element("PersonID").Value == "1" select e; The person table has same structure as the data from nodes. Is it handy to use entity framework/linq-to-xml ? 回答1: If the XML's format is right - i.e. if it uses the same format that the DataSet uses - you can just read it using DataSet.ReadXml() and then use all of the normal ADO tools for