linq-to-xml

How to query an XDocument with LINQ when elements have a colon in their name?

回眸只為那壹抹淺笑 提交于 2020-01-01 07:33:09
问题 I am trying to use LINQ to XML in an with the XDocument object. How do you query the result element in the example below? <serv:header> <serv:response> <serv:result>SUCCESS</serv:result> <serv:gsbStatus>PRIMARY</serv:gsbStatus> </serv:response> </serv:header> When I use a statement like this, I get the exception 'Additional information: The ':' character, hexadecimal value 0x3A, cannot be included in a name.' XDocument doc = XDocument.Parse(xml); string value = doc.Descendants("serv:header")

Parsing xml with XDocument and XPath

倾然丶 夕夏残阳落幕 提交于 2020-01-01 06:20:49
问题 <REETA xmlns="http://pria.org"> <AFFIDAVIT> <COUNTY_NAME>BOBBIES COUNTY</COUNTY_NAME> <DOC_TYPE>DEED</DOC_TYPE> <DOC_DATE>2010-02-19T05:14:58</DOC_DATE> <GROSS_SELL_PRICE>200000.00</GROSS_SELL_PRICE> <TAXABLE_SELL_PRICE>200000.00</TAXABLE_SELL_PRICE> <EXCISE_TAX_STATE>2560.00</EXCISE_TAX_STATE> <EXCISE_TAX_LOCAL>500.00</EXCISE_TAX_LOCAL> <DELQ_INT_STATE>0.00</DELQ_INT_STATE> <DELQ_INT_LOCAL>0.00</DELQ_INT_LOCAL> <DELQ_PENALTY>0.00</DELQ_PENALTY> <SUB_TOTAL>3060</SUB_TOTAL> <STATE_TECH_FEE>5

convert XmlNode to XNode?

 ̄綄美尐妖づ 提交于 2020-01-01 04:38:05
问题 Anyone know off the top of their heads how to convert a System.Xml.XmlNode to System.Xml.Linq.XNode? 回答1: I've never tried, but my first thought would be something like: XmlNode myNode; XNode translatedNode = XDocument.Parse(myNode.OuterXml); 回答2: Eric White's blog is the place to be for cool XML/XLINQ conversions and such. I know this question pre-date's the post but I found it while looking at some other Q, so maybe people still come across this a fair amount. His blog has plenty of

Performance: XmlReader or LINQ to XML

筅森魡賤 提交于 2019-12-31 17:39:30
问题 I have a 150 MB XML file which is used as DB in my project. Currently I'm using XmlReader to read content from it. I want to know if it is better to use XmlReader or LINQ to XML for this scenario. Note that I'm searching for an item in this XML and display search result, so it can take a long time or just a moment. 回答1: If you want performance use XMLReader. It doesn't read the whole file and build the DOM tree in memory. It instead, reads the file from disk and gives you back each node it

Performance: XmlReader or LINQ to XML

时间秒杀一切 提交于 2019-12-31 17:39:15
问题 I have a 150 MB XML file which is used as DB in my project. Currently I'm using XmlReader to read content from it. I want to know if it is better to use XmlReader or LINQ to XML for this scenario. Note that I'm searching for an item in this XML and display search result, so it can take a long time or just a moment. 回答1: If you want performance use XMLReader. It doesn't read the whole file and build the DOM tree in memory. It instead, reads the file from disk and gives you back each node it

Select attribute from xml element

℡╲_俬逩灬. 提交于 2019-12-31 05:16:08
问题 I'm trying to select an attribute from my root node but i keep getting a null exception on the select part. What's the correct way of getting the value of my attribute? The value i am trying to get value of the attribute: SymbolicName The xml document: <Bundle xmlns="urn:uiosp-bundle-manifest-2.0" Name="ContactUsPlugin" SymbolicName="ContactUsPlugin" Version="1" InitializedState="Active"> <Activator Type="ContactUsPlugin.Activator" Policy="Immediate" /> <Runtime> <Assembly Path="bin

Serializing a list of objects to XDocument

会有一股神秘感。 提交于 2019-12-31 05:01:29
问题 I'm trying to use the following code to serialize a list of objects into XDocument, but I'm getting an error stating that "Non white space characters cannot be added to content " public XDocument GetEngagement(MyApplication application) { ProxyClient client = new ProxyClient(); List<Engagement> engs; List<Engagement> allEngs = new List<Engagement>(); foreach (Applicant app in application.Applicants) { engs = new List<Engagement>(); engs = client.GetEngagements("myConnString", app.SSN.ToString

Parse XML Elements with LINQ

妖精的绣舞 提交于 2019-12-31 03:45:09
问题 I have this xml. <?xml version="1.0" encoding="utf-8"?> <feed xml:lang="el-gr" xmlns="http://www.w3.org/2005/Atom"> <title type="text">name.gr</title> <updated>2011-07-23</updated> <link href="link" /> <entry> <title type="html">Οι επιθέσεις σε σκανδιναβικές χώρες</title> <summary type="text">Η Νορβηγία, μία από τις σκανδιναβικές χώρες, έζησε μετά από πάρα πολλά χρόνια (2006) τον τρόμο. Δείτε αναλυτικά τις τελευταίες «τυφλές» επιθέσεις τα τελευταία χρόνια:...</summary> <published>2011-07

Merge XElement into XDocument and resolve namespaces

本小妞迷上赌 提交于 2019-12-31 03:36:07
问题 Given the following XDocument , initialized into variable xDoc : <Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"> <ReportSection> <Width /> <Page> </ReportSections> </Report> I have a template embedded in an XML file (let's call it body.xml ): <Body xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"> <ReportItems /> <Height /> <Style /> </Body> Which I would like to put as a child of <ReportSection> . Problem is if add

Strategy for parsing LOTS and LOTS of not-so-well formed SGML / XML documents

我只是一个虾纸丫 提交于 2019-12-31 03:24:06
问题 I have thousands of SGML documents, some well-formed, some not so well-formed. I need to get at certain ELEMENTS in the documents, but everytime I go to load and try to read them into an XDocument, XMLDocument, or even just a StreamReader, I get different various XMLException errors. Things like "'[' is an unexpected token.". Why? Because I have a document with DOCTYPE like <!DOCTYPE RChapter PUBLIC "-//LSC//DTD R Chapter for Authoring//EN" [] > and I have learned that the "[]" needs to have