linq-to-xml

Add Stylesheet reference to XML Document in Linq?

核能气质少年 提交于 2020-01-03 08:28:10
问题 I create an XML Doc and wanted have a reference to the XSLT file. //<?xml-stylesheet type="text/xsl" href="OBReport.xslt"?> to this XML generation: XElement xml = new XElement("ReportedOn", from dl in EL.DocumentLog.ToList() join o in EL.Organization on dl.OrganizationID equals o.OrganizationId where dl.ActionDate >= stDate & dl.ActionDate <= enDate orderby dl.DefendantName, dl.DocumentName select new XElement("persons", new XAttribute("documentName", dl.DocumentName), new XElement(

Copying part of an xml document to another document using Xdocument

天大地大妈咪最大 提交于 2020-01-03 05:17:08
问题 I have an xml document which is roughly as follows <Gov> <Head> <address></address> <address></address> </Head> <Body> <line1></line1> <line1></line1> </Body> <Gov> I need to copy everything in the body(and including) to a new XDocument. What is the best way to 回答1: Here is an example of copying data "xml" from one document to another.With selection of personalized node First you need convert Xdocument to XmlDocument: using System; using System.Xml; using System.Xml.Linq; namespace MyTest {

how to convert data base data to XML file

六眼飞鱼酱① 提交于 2020-01-02 14:05:14
问题 Q: I'm a beginner to the XML.I have some data comes from my database, and i wanna to convert these data to XML file,to import it to a specific program later..What are the required steps to do this?Please examples and articles if possible? need some thing like that ,but dynamically. 回答1: GetXml() is the function with DataSet to get xml. DataSet ds = new DataSet(); // fill dataset from database ds.GetXml(); Hope will Help. 回答2: DataSet ds = new DataSet(); ds.Tables.Add("DataTableName"); ds

Easiest way to filter elements out of an XML document in .NET

佐手、 提交于 2020-01-02 09:54:03
问题 Let's say I have the following doc <sets version="2.0"> <setting> <id>set1</id> <value>80</value> <label>EVersion</label> <type>Val</type> <format>R</format> <bits> <addr>0</addr> <startBit>0</startBit> <bitWidth>8</bitWidth> </bitspec> </setting> <setting> <id>set3</id> <value>50</value> <label>GVersion</label> <type>Bin</type> <format>R</format> <bits> <addr>0</addr> <startBit>0</startBit> <bitWidth>8</bitWidth> </bitspec> </setting> </sets> and I just want the ID and value elements - <sets

How do i get all “properties” from xml via linq to xml

南楼画角 提交于 2020-01-02 04:59:07
问题 XML sample (original link): <records> <record index="1"> <property name="Username">Sven</property> <property name="Domain">infinity2</property> <property name="LastLogon">12/15/2009</property> </record> <record index="2"> <property name="Username">Josephine</property> <property name="Domain">infinity3</property> <property name="LastLogon">01/02/2010</property> </record> <record index="3"> <property name="Username">Frankie</property> <property name="Domain">wk-infinity9</property> <property

XDocument XDeclaration not appearing in ToString result

老子叫甜甜 提交于 2020-01-02 04:53:06
问题 I am trying to form an XML document which I will be using to send as over HTTPS to an API, however I have noticed that even though I have added an XDeclaration element to my XML the XDeclaration does not appear in the string that I return using xmlDoc.ToString() method. Does anyone know if I am missing a particular setting or any reason why the <?xml version="1.0" encoding="UTF-8" ?> elements are not appearing? xmlDoc = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XElement(

C# Adding a root to an XDocument

筅森魡賤 提交于 2020-01-02 02:38:06
问题 I have a string that contains an XML, lets say like this: <Novels> <Book> <Title>Cat in hat</Title> <Price>12</Price> </Book> </Novels> I want to make an XDocument that looks like this: <Booklist> <Novels> <Book> <Title>Cat in hat</Title> <Price>12</Price> </Book> </Novels> </Booklist> I can load the xml string into an XDocument using XDocument doc = XDocument.Parse(xmlString); How would I load the document under a new root. I can think of something like creating a new XDocument with the root

How to query XML data in database column using Linq to SQL and Linq to XML?

僤鯓⒐⒋嵵緔 提交于 2020-01-01 11:36:32
问题 XML: <root> <item> <href>http://myurl</href> </item> <item> <href>http://myurl2</href> </item> </root> The XML data is stored in a database table. Can I build a Linq query which selects the rows, extracts the XML and then, for example, extracts all the href tags? The end result would then be a list of all URLS for all selected rows. This is my attempt, but it is not giving me what I want - which would be a list of all hrefs for all selected users. I just get a list of empty IEnumerations. var

System.XML.XmlException: ' ' is an unexpected token. The expected token is ';'

核能气质少年 提交于 2020-01-01 09:23:12
问题 I have an HTML form that i'm trying to load using XDocument.Load, and i'm receiving the following error: ' ' is an unexpected token. The expected token is ';'. Line 1257, position 66. at System.Xml.XmlTextReaderImpl.Throw(Exception e) The code is just calling the following: XDocument xmlDoc = XDocument.Load(pageData.Stream); pageData is a custom object from another system, that is spitting out a datastream. I've had it export the xml back out to a string, and it looks fine. When i check that

Parse XDocument without having to keep specifying the default namespace

*爱你&永不变心* 提交于 2020-01-01 08:15:10
问题 I have some XML data (similar to the sample below) and I want to read the values in code. Why am I forced to specify the default namespace to access each element? I would have expected the default namespace to be used for all elements. Is there a more logical way to achieve my goal? Sample XML: <?xml version="1.0" encoding="UTF-8"?> <ReceiptsBatch xmlns="http://www.secretsonline.gov.uk/secrets"> <MessageHeader> <MessageID>00000173</MessageID> <Timestamp>2009-10-28T16:50:01</Timestamp>