How can I load the following formatted XML document:
<Settings>
<MimeTypes>
<MimeType Type="application/mac-binhex40" Extensions=".hqx"/>
<MimeType Type="application/msword" Extensions=".doc;.docx"/>
<MimeType Type="application/pdf" Extensions=".pdf"/>
<MimeType Type="application/vnd.ms-excel" Extensi...
I'm having a devil of a time selecting the value of a single element in my XML document
My document looks like
<?xml version="1.0" encoding="utf-8" ?>
<MySettings>
<AttachmentsPath>Test</AttachmentsPath>
<PendingAttachmentsPath>Test2</PendingAttachmentsPath>
</MySettings>
I've tried to do the following:
XElement mySettings = X...
I am learning LINQ and this seems like a fairly simple problem. I have a semi-working solution but I am sure it could be cleaned up.
The propertyAuto node represents a car with id = 606.
This node needs to have at least two child propertyValue nodes, one that references a vehicleValuation element with attribute of "Book" and one of "Au...
Anyone knows the problem why linq to xml or xpath extensions cant seem to read this xml?
http://www.quillarts.com/Test/product.xml
var document = XDocument.Load(feedUrl);
var xpathxml = from feed in document.XPathSelectElements("//Products") //using Xpath
var linqtoxml = from feed in document.Descendants("Products") //using Linq2XML
...
Anyone knows why this xpath expression "catzero/@id" is not working on this xml
document = XDocument.Load("file.xml");
var product = document.XPathSelectElements("//product", nameSpaceResolver).First();
var category = ((IEnumerable) product.XPathEvaluate("catzero/@id")).Cast<XAttribute>().first().value; //catezero/@id is null
...
This is what I got:
<xml>I need this text<notthistext>blahblah<notthistext></xml>
How can I get:
I need this text
I am using .value and it is returning the text for everything like this:
I need this textblahblah
...
I have an xml that I am querying. One of the nodes is missing. So when I call XElement.Value I get a null exception.
What is the best way to guard against this? I know I can write an extension method, but I am wondering is there something build into the language for this?
...
I have an xml file that is like this:
<xml>I need this text<notthistext>blahblah<notthistext></xml>
I get the text by doing something like this:
var mycollection = from myNode in myDoc.descendents("xml") select new { test = Convert.ToString(myNode.Nodes().First())}
but the problem is that there are carrige returns and spaces that d...
Is it possible to combine Linq-to-SQL and Linq-to-XML if a column of a table is XML?
...
I sometimes do this:
XElement.Descendants("mynodename");
is there a way to do something like this"
XElement.Descendants("mynodename or myothernodename");
...
Currently I'm using the following extension method that I made to retrieve the values of elements using LINQ to XML. It uses Any() to see if there are any elements with the given name, and if there are, it just gets the value. Otherwise, it returns an empty string. The main use for this method is for when I'm parsing XML into C# objec...
FYI, This is very similar to my last question: Is there a faster way to check for an XML Element in LINQ to XML?
Currently I'm using the following extension method that I made to retrieve the bool values of elements using LINQ to XML. It uses Any() to see if there are any elements with the given name, and if there are, it parses the val...
FYI, This is very similar to my last question: Is there a faster way to check for an XML Element in LINQ to XML, and parse a bool?
Currently I'm using the following extension method that I made to retrieve the int values of elements using LINQ to XML. It uses Any() to see if there are any elements with the given name, and if there are, ...
Hello all,
I am working with some large XML files using LINQ to XML. Now, a typical XML file returns:
ID
Name
Image URL
I get a lot of duplicate information, I consider duplicate information to be data with the same ID ( it could have different a name and images and I don't mind). I want to distinct the values of the first XML file ...
I am trying to extract information from an XML file into an object using LINQ to XML. Although I can return the document and section Id attributes I cannot get access to the Items for each section element, it returns an IEnumerable of all the items in the document. I know this is correct as I’m calling Descendants but am struggling to ge...
I'm trying to create a spreadsheet in XML Spreadsheet 2003 format (so Excel can read it). I'm writing out the document using the XDocument class, and I need to get a newline in the body of one of the <Cell> tags. Excel, when it reads and writes, requires the files to have the literal string embedded in the string to correctly sho...
// Remove element with ID of 1
var userIds = from user in document.Descendants("Id")
where user.Value == "1"
select user;
userIds.Remove();
SaveAndDisplay(document);
// Add element back
var newElement = new XElement("Id", "0",
ne...
I get a null exception on this because MYTAG1 doesn't exist. I understand that this is because Element("MYTAG1") is null and calling Elements("MYTAG2") on it wont work.
How do I deal with this to prevent the crash?
var myItems = from myNode in Nodes.Element("MYTAG1").Elements("MYTAG2")
select new EPTabl...
My XML:
<content>
<item id="1">A</item>
<item id="2">B</item>
<item id="4">D</item>
</content>
I have loaded this using XML similar to:
XDocument xDoc = new XDocument(data.Value);
var items = from i in xDoc.Element("content").Elements("item")
select i;
I want to insert another element, to end up with something like:...
Linq-to-Xml contains lots of methods that allow you to add arbitrary objects to an xml tree. These objects are converted to strings by some means, but I can't seem to find the specification of how this occurs. The conversion I'm referring to is mentioned (but not specified) in MSDN.
I happen to need this for javascript interop, but th...