linq-to-xml

LINQ to XML issue due to xml namespace

你离开我真会死。 提交于 2019-12-12 09:48:31
问题 I am trying to use Linq to select from XML. Here is an example of the XML: <?xml version="1.0" encoding="UTF-8"?> <listingexport xmlns="http://websitexmlfeed.com/webservice/2/listings" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websitexmlfeed.com/webservice/2/listings ../listings.xsd"> <listing> <id>00001</id> <name>Modelname</name> <type>Typename</type> </listing> </listingexport> The code I am using is as follows: XDocument le = XDocument.Load(@uri);

How can I get the first element after an element with LINQ-to-XML?

回眸只為那壹抹淺笑 提交于 2019-12-12 08:00:00
问题 With this code I can get the title out of the following XML file: var xml = XElement.Load (@"C:\\test\\smartForm-customersMain.xml"); string title = xml.Element("title").Value; But how do I make it more exact, e.g. "get the first element after the smartForm element , e.g. something like this: //PSEUDO-CODE: string title = xml.Element("smartForm").FirstChild("title"); The XML: <?xml version="1.0" encoding="utf-8" ?> <smartForm idCode="customersMain"> <title>Customers Main222</title>

C# Querying an XML Document

限于喜欢 提交于 2019-12-12 06:46:18
问题 Good Day, I am trying to query an XML document and have the following query: XElement root = XElement.Load(@"..\..\Data.xml"); var entries = root.Descendants() .Where(x => x.Name.LocalName == "Entry") .ToList(); Console.WriteLine("There are {0} nodes...", entries.Count()); foreach (XElement v in entries) { Console.WriteLine(v.Value); } and this code works because it pulls the correct number of Entry nodes. The Entry nodes look like: <?xml version="1.0" encoding="UTF-8"?> <Database xmlns="http

Deleting an element from XML document and saving over old file

限于喜欢 提交于 2019-12-12 05:21:50
问题 *EDIT: ok, so I got the program to delete, the line foreach (var elem in doc.Document.Descendants("Profiles")) needed "Profile" instead. BUT now in my XML doc there is an empty Profile Element for each one deleted, so If all the items in the xml example(at bottom of question) get deleted I'm left with this: * <?xml version="1.0" encoding="utf-8"?> <Profiles> <Profile /> <Profile /> </Profiles> =========================ORIGINAL QUESTION BELOW================================= I'm using the

Remove all text nodes from XML file

点点圈 提交于 2019-12-12 05:16:31
问题 I want to remove all text nodes (but not any other type of node) from an XML file. How can I do this? Example Input: <root> <slideshow id="1"> <Image>hii</Image> <ImageContent>this</ImageContent> <Thumbnail>is</Thumbnail> <ThumbnailContent>A</ThumbnailContent> </slideshow> <slideshow id="2"> <Image>hii</Image> <ImageContent>this</ImageContent> <Thumbnail>is</Thumbnail> <ThumbnailContent>B</ThumbnailContent> </slideshow> </root> Expected Output: <root> <slideshow id="1"> <Image></Image>

Replace the root node in XDocument

ⅰ亾dé卋堺 提交于 2019-12-12 05:15:10
问题 Is it possible to replace the root element of an XDocument? I currently have a document that looks like: <ArrayOfCompletedInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <CompletedInvoice> <Invoice>1</Invoice> ... </CompletedInvoice> </ArrayOfCompletedInvoice> I want it to look like: <ns0:CompletedInvoices xmlns:ns0="http://myNamespace"> <CompletedInvoice> <Invoice>1</Invoice> ... </CompletedInvoice> </ns0:CompletedInvoices> I know I

Remove the Parent Node based on Child condition

ぐ巨炮叔叔 提交于 2019-12-12 05:12:03
问题 I need help here to remove the xml node based on some condition Here is my xml <result> <product> <auto> <report> <auto> <admin></admin> <report> <search> <subjects> <subject> <name> <first>John</first> <last>D</last> </name> </subject> </subjects> </search> </report> </auto> </report> </auto> <auto> <report> <auto> <admin></admin> <report> <search> <subjects> <subject> <name> <first>Jack</first> <last>L</last> </name> </subject> </subjects> </search> </report> </auto> </report> </auto> <

Difficulty in reading XML values using XDocument

柔情痞子 提交于 2019-12-12 04:57:15
问题 I have an xml file as under <ScriptFileNames> <SqlEye> <ScriptFile Name='_ws_CommandHistory_AllHistory.sql' Type='SP' SqlEyeAnalysisTime='00:00:01.7817594' FxCopAnalysisTime='00:00:00.2253670' FxCopWarningCount='0' SqlEyeWarningCount='2'> <SqlEyeWarnings> <SqlEyeWarning message='SD004: Check for existence object then Drop statement before create statement' /> <SqlEyeWarning message='SP001: Set NoCount statement missing or it should be ON.' /> </SqlEyeWarnings> </ScriptFile> </SqlEye> <

Parse Xml with same key values

自闭症网瘾萝莉.ら 提交于 2019-12-12 04:46:45
问题 I am working on Windows Phone 8 application, I have some UI which looks like this : Main Item A --- has its desc and list of subitems as key value Main Item B --- has its desc and list of subitems as key value Main Item C --- has its desc and list of subitems as key value Now on click of A move to next page which will display its Description and its sub items. On click of Main Item A Description of Main Item A sub item 1 --- On click of this display its desc sub item 2 --- On click of this

How to get certain elements inside an XML document

送分小仙女□ 提交于 2019-12-12 04:45:41
问题 I am querying my SP list like this: HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://myspsite/_api/web/lists/getByTitle('the%20title')/items"); request.Method = "GET"; request.ContentType = "text/xml"; request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);