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 8193277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:25:39+00:00 2026-06-07T04:25:39+00:00

I am sure that this is basic and probably was asked before, but I

  • 0

I am sure that this is basic and probably was asked before, but I am only starting using Linq to XML.

I have a simple XML that i need to read and write to.

<Documents>
...
    <Document>
      <GUID>09a1f55f-c248-44cd-9460-c0aab7c017c9-0</GUID>
      <ArchiveTime>2012-05-15T14:27:58.5270023+02:00</ArchiveTime>
      <ArchiveTimeUtc>2012-05-15T12:27:58.5270023Z</ArchiveTimeUtc>
      <IndexDatas>
        <IndexData>
          <Name>Name1</Name>
          <Value>Some value</Value>
          <DataType>1</DataType>
          <CreationTime>2012-05-15T14:27:39.6427753+02:00</CreationTime>
          <CreationTimeUtc>2012-05-15T12:27:39.6427753Z</CreationTimeUtc>
        </IndexData>
        <IndexData>
          <Name>Name2</Name>
          <Value>Some value</Value>
          <DataType>3</DataType>
          <CreationTime>2012-05-15T14:27:39.6427753+02:00</CreationTime>
          <CreationTimeUtc>2012-05-15T12:27:39.6427753Z</CreationTimeUtc>
        </IndexData>
   ...
 </IndexDatas>
</Document>
...
</Documents>

I have a “Documents” node that contains bunch of “Document” nodes.

I have GUID of the document and a “IndexData” name.
I need to find the document by GUID and check if it has “IndexData” with some name.
If it does not have it i need to add it.

Any help would be apreciated, as i have problem with reading and searching trough elements.

Currently I am trying to use (in C#):

IEnumerable<XElement> xmlDocuments = from c in XElement
                                        .Load(filePath)
                                        .Elements("Documents") 
                                         select c;

// fetch document
 XElement documentElementToEdit = (from c in xmlDocuments where 
                    (string)c.Element("GUID").Value == GUID select c).Single();

EDIT

xmlDocuments.Element("Documents").Elements("Document")

This returns no result, even tho xmlDocuments.Element(“Documents”) does. It looks like i cant get Document nodes from Documents node.

  • 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-07T04:25:40+00:00Added an answer on June 7, 2026 at 4:25 am

    You can find those docs (docs without related name in index data) with below code, after that you could add your elements to the end of IndexData elements.

    var relatedDocs = doc.Elements("Document")
       .Where(x=>x.Element("GUID").Value == givenValue)
       .Where(x=>!x.Element("IndexDatas")
                  .Elements("IndexData")
                  .Any(x=>x.Element("Name") == someValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sure that this kind of questions must have been asked before, but
I realize that this is probably a very basic question, but I have spent
I have this function I'm using and I want to be sure that it
I am not sure where i've seen this before, but im sure that there
This is probably a pretty basic question, but just something that I wanted to
I am sure that the answer to this has been posted before. Forgive me
I see this question here on SO but I am not sure that answers
Not sure this is possible, but looking to write a script that would return
I have an interesting situation, well it's probably not that unique at all, but
Before anyone says try searching, I have - I realize this is probably a

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.