I was wondering if there is a way to get a list of results into a list with linq to xml. If I would have the following xml for example:
<?xml version="1.0"?>
<Sports xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SportPages>
<SportPage type="test">
<LinkPag...
I've got a program that needs to convert two attributes of a particular tag to the key and value of an Dictionary<int,string>. The XML looks like this:
(fragment)
<startingPoint coordinates="1,1" player="1" />
and so far my LINQ looks something like this:
XNamespace ns = "http://the_namespace";
var startingpoints = from sp in xml.El...
is there a simple way to modify the InnerXml of a XElement?
supose we have this extremely simple xml
<planets>
<earth></earth>
<mercurio></mercurio>
</planets>
and we want to append some xml that come from another source that comes like a string "<continents><america/><europa/>.....blablabla" into the earth node.
I read relat...
Is there a way to search a XDocument without knowing the Namespace? I have a process that logs all SOAP requests and encrypts the sensitive data. I want to find any elements based on name. Something like, give me all elements where the name is CreditCard. I don't care what the namespace is.
My problem seems to be with LINQ and requiri...
OK, bit of a random question, but the best way to do this is to just add the code, you'll be able to see what I mean straight away:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<customers>
<customer>
<id>1</id>
<name>Blah-face</name>
<Type>1</Type>
</customer>
<customer>
<id>2</id>
<name>Blah-face-2</name>
...
Right, starting to go crazy here. I have the following code:
var query = (from c in db.Descendants("Customer")
select c.Elements());
dgvEditCusts.DataSource = query.ToList();
In this, db relates to an XDocument.Load call. How can I get the data into the DataGridView?
Just thought I should ...
Right, bit of a strange question; I have been doing some linq to XML work recently (see my other recent posts here and here).
Basically, I want to be able to create a query that checks whether a textbox is null before it's value is included in the query, like so:
XDocument db = XDocument.Load(xmlPath);
var query = (from vals in db.Desc...
Hi, I am trying to write a query expression to parse an XML tree, but without much luck.
The tree is as follows:
<item>
<itemInfo id="1965339" lang="en" key="title">
<info>Octopuzzle
</info>
</itemInfo>
<itemInfo id="1965337" lang="en" key="longDescription">
<info>"In Octopuzzle you play the Octopu...
I have an XML file that I'm trying to parse with Linq-to-XML. One of the nodes contains a bit of HTML, that I cannot retrieve.
The XML resembles:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<image><img src="/Images/m1cznk4a6fh7.jpg" /></image>
<contentType>Banner</contentType>
</root>
The code is:
XDocument document = XDocum...
Hi,
I have an XML doc like this:
<Persons>
<Person Id="10000" FullName="Jon Doe">
<Status StatusID="1" StatusDesc="Active"/>
<Fields>
<Field FieldId="1" Value="xxxx"/>
<Field FieldId="2" Value="yyyy"/>
<Field FieldId="2" Value="zzzz"/>
</Fields>
</Person>
<Person Id="10001" FullName="John ...
I'm trying to write a Linq2XML query to query the following XML. I need it to pull back all photos for a given GalleryID.
<Albums>
<Album GalleryId="1" Cover="AlbumCover1.jpg" Title="Album 1">
<Photos>
<Photo Title="Image1" URL="img1.jpg" DateAdded="01/01/2010 09:20"/>
<Photo Title="Image2" URL="img2.jpg" DateAdded=...
Repository pattern - Switch out the database and switch in XML files.
Hello
I have an asp.net MVC 2.0 project and I have followed the Repository pattern.
Periodically, I am losing access to the database server so I want to have another mechanism in place (XML files) to continue developing. It is not possible to have a local version of...
I have an XML file like this:
<SiteConfig>
<Sites>
<Site Identifier="a" />
<Site Identifier="b" />
<Site Identifier="c" />
</Sites>
</SiteConfig>
The file is user-editable, so I want to provide reasonable error message in case I can't properly parse it. I could probably write a .xsd for it, but that seems kind of overk...
My code works for ORs as I've listed it below but I want to use AND instead of OR and it fails. I'm not quite sure what I'm doing wrong. Basically I have a Linq query that searches on multiple fields in an XML file. The search fields might not all have information. Each element runs the extension method, and tests the equality. Any ...
How do I get Linq to ignore any parameters that are empty? So Lastname, Firstname, etc? If I have data in all parameters it works fine...
refinedresult = From x In theresult _
Where x.<thelastname>.Value.TestPhoneElement(LastName) And _
x.<thefirstname>.Value.TestPhoneElement(FirstName) And _
...
This query seems to be valid, but I have 0 results.
IEnumerable<XElement> users =
(from el in XMLDoc.Elements("Users")
where (string)el.Attribute("GUID") == userGUID.ToString()
select el);
My XML is as follows:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Users>
<User GUID="68327fe2...
Assuming you have the following XML:
<?xml version="1.0" encoding="utf-8"?>
<content>
<info>
<media>
<image>
<info>
<imageType>product</imageType>
</info>
<imagedata fileref="http://www.example.com/image1.jpg" />
</image>
...
I have the following xml data:
<portfolio>
<item>
<title>Site</title>
<description>Site.com is a </description>
<url>http://www.site.com</url>
<photos>
<photo url="http://www.site.com/site/thumbnail.png" thumbnail="true" description="Main" />
<photo url="http://www.site.com/site/1.png" thumbnail="fals...
<?xml version='1.0' encoding='utf-8' ?>
<All>
<Customers>
<Customer>
<Name> Brisbane </Name>
<age> 18 </age>
<id> 1234 </id>
<type> owner </type>
</Customer>
<details>
<address> 123,brisbane </address>
<locati...
Hi,
i am using a large xml file having in the following format:
<Sales>
<Sale>
<Date>04/20/2010</Date>
<Time>18:17:29</Time>
<Id>P00000001</Id>
<Name>Prod Name</Name>
<Description>Prod Desc</Description>
<Category>Prod Category</Category>
<Subcategory>Prod Subcategory</Subcategory>
<Size>Prod Size</Si...