I have a piece of xml like the following:
<Table>
<Record>
<Field>Value1_1</Field>
<Field>Value1_2</Field>
</Record>
<Record>
<Field>Value2_1</Field>
<Field>Value2_2</Field>
</Record>
</Table>
What i would like is a LINQ query that generates an IEnumerable that i can assign as the datasource of a DataGrid. What...
Background
We have a project that was started in .NET 1.1, moved to .NET 2.0, and recently moved again to .NET 3.5. The project is extremely data-driven and utilizes XML for many of its data files. Some of these XML files are quite large and I would like to take the opportunity I currently have to improve the application's interaction w...
Say I call XElement.Parse() with the following XML string:
var xml = XElement.Parse(@"
<?xml version="1.0" encoding="UTF-8"?>
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>7c75442509c41100b6a413b88b523bd6f46554cdbee5b6cbe27bc08cb3f6a865</ID>
<DisplayName>me</DisplayName>
</...
I've been feeling like start doing some fun stuff with my delicious bookmarks and LINQ to XML, and I was wondering if there's a way to split the tag attribute within LINQ.
What I've meant with split the tag within LINQ was generating a collection of strings for each post element, so the expected result would be a generic collection of p...
I'm fooling around trying to learn the ins an outs of LINQ. I want to convert the following query (which is working correctly) from query syntax to method syntax, but I can't seem to get it right. Can anyone show me the correct way to accomplish that?
var logQuery = from entry in xDoc.Descendants("logentry")
...
In this query, I always want the 'normal' type element.
If the _includeX flag is set, I want the 'workspace' type elements, too.
Is there a way to write this as one query? Or build the where clause based on _includeX before submitting the query?
TIA...
if (_includeX) {
query = from xElem in doc.Descendants(_xString)
le...
Trying to parse an HTML document and extract some elements (any links to text files).
The current strategy is to load an HTML document into a string. Then find all instances of links to text files. It could be any file type, but for this question, it's a text file.
The end goal is to have an IEnumerable list of string objects. That par...
It's a novice question so be kind to me :)
How can I consume a php API in ASP.NET? This API returns an XML document. It is also capable of returning JSON.
The output is shown below
XML
<?xml version="1.0" encoding="UTF-8"?>
<Address>
<Country>US</Country>
<City>Seattle</City>
<Result>Done</Result>
</Addre...
Greetings!
I have an XElement object that contains the following:
<Root>
<SubSections>
<SubSection id="A">
<Foo id="1">
<Bar />
<Bar />
<Bar />
</Foo>
<Foo id="2">
<Bar />
<Bar />
</Foo>
...
Let´s say I have the following xml,
<Where><BeginsWith>...</BeginsWith></Where>
and now I want to "insert" an <And> clause that surrounds the BeginsWith clause so it looks like this afterward,
<Where><And><BeginsWith>...</BeginsWith></And></Where>
How do I accomplish that with LinqToXml?
The Add method where I essentially do
wher...
I recently asked a question regarding how to Save a list with nested elements to XML but now I am trying to write the loader for the class and have run into problems with it.
I am attempting to reverse the answer given (thanks Jon).
I believe my core LINQ query is ok, it is the recursion I am struggling with.
Here is my code so far (fo...
I have Xml which looks like this:
<DataMapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SqlTable />
<Level_01s>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Children>
<DataParameter>
<SqlTable>MY-Table-Name</SqlTable>
<Ch...
Is there any way to have an XDocument print the xml version when using the ToString method? Have it output something like this:
<?xml version="1.0"?>
<!DOCTYPE ELMResponse [
]>
<Response>
<Error> ...
I have the following:
var xdoc = new XDocument(new XDocumentType("Response", null, null, "\n"), ...
which will print this which is fine...
Hi,
in a ASP.NET application (MVC) I have a foreach loop that loops through a structure that may contain or not some element:
<% foreach (XElement segnalazione in ((XElement)ViewData["collezioneSegnalazioni"]).Elements("dossier")) { %>
<tr>
<td><%= Html.Encode(segnalazione.Element("NUM_DOSSIER").Val...
Hi,
I am trying to use Linq to XML to save & retrieve some HTML between an XML file and a windows forms application. When it saves it to the XML file the HTML tags get xml encoded and it isn't saved as straight HTML.
Example HTML:
<P><FONT color=#004080><U>Sample HTML</U></FONT></P>
Saved in XML File:
<P><FONT color=#00408...
I'm loading XML data into an object with this LINQ statement:
var smartFormFields = from smartFormField in xmlDoc.Descendants("smartFormField")
select new Models.SmartFormField
{
IdCode = smartFormField.Element("idCode").Value,
Label = smartF...
In this question Jon Skeet offered a very interesting solution to making a LINQ-to-XML statement dynamic, but my knowledge of lambdas and delegates is not yet advanced enough to implement it:
I've got it this far, but of course I get the error "smartForm does not exist in the current context":
private void LoadWithId(int id)
{
XDoc...
I've got an XML file which I use to create objects, change the objects, then save the objects back into the XML file.
What do I have to change in the following code so that it extracts a node from the XML based on the id, replaces that node with the new one, and saves it back into the XML?
The following gives me 'System.Xml.Linq.XEleme...
I have a WPF application which saves its data to XML files in a relative-to-code directory called "Data".
I get the relative path to the Data directory with these methods:
protected string ApplicationPath
{
get { return System.IO.Path.GetDirectoryName(System.Reflection.Assembly
.GetExecutingAssembly().CodeBase); }
}
prot...
I have an XML configuration file that contains a list of documents with field maps for each document. I want to use LINQ to XML to populate an internal data structure which represents the documents as a hierarchy of List<> structures.
An attribute called Include determines whether the field should be included.
Here is a sample of what ...