I am not getting this Linq thing. I can write complex SQL queries and have written a few xpaths. I am trying to learn Linq to XML and cannot get past my first try despite poring over every terse example I can Google.
Given XML:
<Manufacturer ManufacturerName="Acme">
<Model ModelName="RobotOne">
<CommandText CommandName="MoveForward"...
My xml looks like this
<Element> text <B>text<B></Element>
Unknown number of B tags or tags even of a different name.
How do i get the text from these? so it would be like this
text text
using linq to xml
...
I have xml like this:
<A><B>test</B><B><B>test2</B></B><B><B><B>test2</B></B></B></A>
How can I get the level of each of these items using linq to xml
level of test=1 level of test2=2 level of test3=3
I have no idea how many nodes there will be or how many levels there will be. I can write this as a recursive function but I thought...
I am trying to get an XHTML file loaded into an LINQ XElement. However, I am running into problems with the resolver. The problem has to do with the following definition:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I have a custom XmlUrlResolver with an o...
I can't seem to find anything other than XDocument.Descendants () in the documentation. Is there any way to do this?
...
hi all,
I know how to write to xml files, but I'm having trouble doing what I need to do and can't find adequate info on this type of problem.
Here's one xml file below:
<?xml version="1.0" encoding="utf-8"?>
<controls>
<Label Content="Double-click to edit." Location="258, 178" Size="101, 13" ForeColor="-1" />
<LinkLabel Con...
Hello,
I have an Xml file. It's format is as follows:
ControlType > Content > LocationX > LocationY > ForeColor/LinkColor > Int > Int > Int > Int
File example:
<?xml version="1.0" encoding="utf-8"?>
<cs>
<Label Content="Double-click to edit." LocationX="583" LocationY="254" A="255" R="255" G="255" B="255" />
<LinkLabel Content="...
Hello.
lets say that I've got this XML:
<items>
<item name="thumb">
<downloadStream>test1</downloadStream>
<downloadStream>test2</downloadStream>
<downloadStream>test3</downloadStream>
</item>
<item name="photo">
<downloadStream>test5</downloadStream>
<downloadStream>test6</downloadStream>
<downl...
I need to read, edit and save one xml file. In other words, I want to write again over the same file and not to create a new xml file. Reading and editing parts work, but not the saving.
The Linq-to-Xml code for saving is simply:
doc.Save(this.Path);
This works in iPhone Simulator but throws System.UnauthorizedAccessException on the ...
I'm trying to create an XML file using C# and Linq to XML, but am having problems with the nant namespace.
var myXElement = new XElement("project", new XAttribute("name", "MySystemName"), new XAttribute("default", "myNAntTargetName"), new XAttribute("xmlns", "http://nant.sf.net/schemas/nant.xsd"));
myXElement.Save("c:\foo.xml");
Beca...
I have an XML file that I want to base some unit tests off of. Currently I load the XML file from disk in the class initialize method. I would rather have this xml generated in the test instead of reading the file from disk. Are there any utilities that will automatically generate the linqtoxml code to generate a given XML file? Or a...
Let's say I have nodes like so:
<Params>
<Param val="C" />
<Param val="D" />
<Param val="A" />
<Param val="B" />
<Params>
If I select the Descendants of Params is the order always preserved? I want C to always be first when I iterate through the ordered list that I'll be dropping these into. Or do I need to come up with a differe...
I want to read a large xml file (100+M). Due to its size, I do not want to load it in memory using XElement. I am using linq-xml queries to parse and read it.
What's the best way to do it? Any example on combination of XPath or XmlReader with linq-xml/XElement?
Please help. Thanks.
...
In C#, I need to create XML files for use with Ivy and NAnt, but am having difficulty in getting the right encoding in the output file.
If I use XElement's .Save("C:\foo.xml"), I get the correct looking file, but Ivy and/or NAnt gets upset, as the file is actually saved using UTF-8 but I actually need to save it as ANSI in order to be a...
How do I take this XML and filter out the menu element that is marked as expert using XLINQ and return the rest?
<data>
<preferences />
<menus>
<menu type="expert">
<sub />
</menu>
<menu type="beginner">
<sub />
</menu>
</menus>
</data>
So the result would be:
<data>
<preferences ...
I am trying to query this very complicated XML document using xDocument and LINQ to XML. I want to perform the following action:
Get all elements that answer to a certain criteria, and if they don't, return another attribute from the xDocument.
Example:
<cars>
<car>
<patrol type="oil">
<url> http://Toyotaoil.co...
Can somebody explain why is this xml
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="77" cityID="EE12345" cityDatum="15.2.2010. 11:28:35" />
</items>
when using query
Dim c = From items In st.Descendants _
Where items.@id IsNot Nothing _
Select New myStorage With {.id = items.@id, .cityID = items.@city...
hi. i have the following xml
<students>
<student>
<id>12</id>
<name>Mohsan</name>
</student>
<student>
<id>2</id>
</student>
<student>
<id>3</id>
<name>Azhar</name>
</student>
</students>
note that in 2 name element is missing.
i have to read this xml using Linq to XML
i used following code to ge...
hi i have the following xml
<students>
<student>
<id>12</id>
<name>Mohsan</name>
</student>
<student>
<id>2</id>
<name>Ali</name>
<address>
<country>Pakistan</country>
</address>
<address>
<country>India</country>
</address>
<parent>
<id>12</id>
<address>
<country...
I'm parsing a string of XML into an XDocument that looks like this (using XDocument.Parse)
<Root>
<Item>Here is "Some text"</Item>
</Root>
Then I manipulate the XML a bit, and I want to send it back out as a string, just like it came in
<Root>
<Item>Here is "Some text"</Item>
<NewItem>Another item</NewItem>
...