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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:14:55+00:00 2026-06-13T23:14:55+00:00

I need to inject some XML into a pre-existing XML file under a certain

  • 0

I need to inject some XML into a pre-existing XML file under a certain node. Here is the code I have to create my XML:

//Define the nodes
XElement dataItemNode = new XElement("DataItem");
XElement setterNodeDisplayName = new XElement("Setter");
XElement setterNodeOU = new XElement("Setter");

//Create the tree with the nodes
dataItemNode.Add(setterNodeDisplayName);
dataItemNode.Add(setterNodeOU);

//Define the attributes
XAttribute nameAttrib = new XAttribute("Name", "OrganizationalUnits");
XAttribute displayNameAttrib = new XAttribute("Property", "DisplayName");
XAttribute ouAttrib = new XAttribute("Property", "OU");

//Attach the attributes to the nodes
setterNodeDisplayName.Add(displayNameAttrib);
setterNodeOU.Add(ouAttrib);

//Set the values for each node
setterNodeDisplayName.SetValue("TESTING DISPLAY NAME");
setterNodeOU.SetValue("OU=funky-butt,OU=super,OU=duper,OU=TMI,DC=rompa-room,DC=pbs,DC=com");

Here is the code I have so far to load up the XML document and try to get the node that I need to insert my XML under:

//Load up the UDI Wizard XML file
XDocument udiXML = XDocument.Load("UDIWizard_Config.xml");

//Get the node that I need to append to and then append my XML to it
XElement ouNode = THIS IS WHAT I DONT KNOW HOW TO DO
ouNode.Add(dataItemNode);

Here is the XML from the existing document I am trying to work with:

<Data Name="OrganizationalUnits">
        <DataItem>
          <Setter Property="DisplayName">TESTING DISPLAY NAME</Setter>
          <Setter Property="OU">OU=funky-butt,OU=super,OU=duper,OU=TMI,DC=rompa-room,DC=pbs,DC=com</Setter>
        </DataItem>

I have multiple nodes that with the name of “Data”, but I need to get the node that is , and I don’t know how. Just learning how to use XML with C#.

Thank you.

  • 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-13T23:14:56+00:00Added an answer on June 13, 2026 at 11:14 pm

    This will get the first Data node with Name attribute matching OrganizationalUnits:

    var ouNode = udiXML
        .Descendants("Data")
        .Where(n => n.Attribute("Name") != null)
        .Where(n => n.Attribute("Name").Value == "OrganizationalUnits")
        .First();
    

    If your document might contain Data nodes without Name attribute, extra check for null might be necessary.

    Note that you can achieve the same result with XPath (this will select root Data node, you can get DataItem node using Element method):

    var ouNode = udiXML.XPathSelectElement("//Data[@Name = 'OrganizationalUnits']");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to inject some JavaScript into an existing application. The application is normally
I'm using background page and I need to inject some code into current tab
Need some regular expressions help. So far I have my code working to allow
I need to Inject some global service (daoFactory) into EventListenet subscribed on PostUpdate event.
Two Delphi programs need to load foo.dll, which contains some code that injects a
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
I have a specific case here in which I would like some security advice.
I have some XML that looks something like the one below <DriveLayout> <Drive totalSpace=16
Want to clear some confusion. I have applicationContext.xml. Question 1: Whats the difference between
I have some code that consists of a lot (several hundreds of LOC) of

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.