Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8351153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:32:42+00:00 2026-06-09T08:32:42+00:00

I have an XElement object that was created by parsing the XML from a

  • 0

I have an XElement object that was created by parsing the XML from a word document. What I want to do is find and remove a specific node that I am trying to find using LINQ.

The XML is a couple hundred lines long so I don’t want to post the whole thing here, I will just show the first 20 lines:

<w:body xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
    <w:p w:rsidR="00CB3A3E" w:rsidP="00257CF7" w:rsidRDefault="008C1E91">
        <w:pPr>
            <w:pStyle w:val="Heading-Title" />
        </w:pPr>
        <w:r>
            <w:t>References</w:t>
        </w:r>
    </w:p>
    <w:sdt>
        <w:sdtPr>
            <w:alias w:val="Client" />
            <w:tag w:val="ClientName" />
            <w:id w:val="-1008363323" />
            <w:lock w:val="contentLocked" />
            <w:placeholder>
                <w:docPart w:val="DefaultPlaceholder_1082065158" />
            </w:placeholder>
            <w:dataBinding w:xpath="/project[1]/ClientName[3]" w:storeItemID="{1BDA6E50-A0B2-47FF-9929-1F045B6CF8AD}" />
            <w:text />

The node I want to remove is : <w:t>References</w:t> . I am currently getting a “Sequence contains no elements" exception. newBody is the XElement.

newBody.Descendants.Where(Function(e) e.Name.Equals("<w:t>") AndAlso e.Value.Equals("References")).First().Remove()

As I said I am getting the exception noted above. Is this how I should be attempting to get to this node? Is there a better way? Why is my query not getting the specified node? ANy advice on how to do this better is very much appreciated, I’m still trying to learn best practices when it comes to XML traversal in .net and LINQ itself. Thanks much!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:32:45+00:00Added an answer on June 9, 2026 at 8:32 am

    I’m making a little bit of a guess here since this is VB.net and I come from a C# background, but the LINQ part looks the same. I think your problem lies with the Name.Equals("<w:t>") part. Name is not a string but an XName and it has a few more properties. Most likely you need to look at Name.LocalName.Equals("t"):

    .Where(Function(e) e.Name.LocalName.Equals("t")) AndAlso e.Value.Equals("References"))
    

    As for the second part of your question, if you just want to remove one node, then navigating to that one specific node is most likely far more efficient than making a document global rule to which only one node matches. My approach to you problem would be more like this:

    newBody.Element("p").Element("r").Element("t").Remove();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XElement object which is my XML tree read from XML file. Now
I want to find the Xelement attribute.value which children have a concrete attribute.value. string
I have the following XML Parsing code in my application: public static XElement Parse(string
Greetings! I have an XElement object that contains the following: <Root> <SubSections> <SubSection id=A>
I have an Xml document that looks similar too <Reports xmlns=> <Report> <ReportID>1</ReportID> <ParameterTemplate
I have been working with XML in database LINQ and find that it is
I have a situation where I have an xml file that I don't want
I have an XML File that I am processing using LINQ. I want to
I have an XElement object which has a number of attributes and I simply
If I have the following xml: XDocument xDocument = new XDocument( new XElement(RootElement, new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.