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

  • Home
  • SEARCH
  • 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 8984275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:03:38+00:00 2026-06-15T21:03:38+00:00

Using some example code I found here on SO , I’ve put together a

  • 0

Using some example code I found here on SO, I’ve put together a bit of code to open up an existing XML database, open up another XML file that’s to be inserted into the first XML, get the descendants of the root node in that file, and append them to the base of the selected node in the database.xml file, and then save the resultant file to a new XML file. The code below compiles & runs with no errors in VS2010, but doesn’t add the XML from the actionID.xml file to the database.xml file and I don’t know what I’m missing.

Here’s the C# code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class pcbdbUpdate
{
static void Main( )
    {
        //open database & load into memory
        XDocument PCBDB = XDocument.Load("C:\\database.xml");
        //open Activity Log file & load into memory
        XDocument addAction = XDocument.Load("C:\\actionID.xml");
        //get descendant node(s) below PCBDBActivityLog root node
        var actionXML = addAction.Root.Descendants("PCBDBActivityLog");
        /*supposed to write out child nodes, but not very useful, just tells me
        it's a:  System.Xml.Linq.XContainer+<GetDescendants>d__a*/
        Console.WriteLine(actionXML.ToString());
        //enumerate database for SBE_PCB_Data nodes
        IEnumerable<XElement> SBE_PCB_Data = PCBDB.Element("PCBDatabase").Elements("SBE_PCB_Data");
        //look for specific node with PCBID of "00001" and select it
        XElement newAction = SBE_PCB_Data.Where(p => p.Attribute("PCBID").Value == "00001").FirstOrDefault();
        //write descendants from Activity Log to base of node
        newAction.Add(actionXML);
        //save the resultant file
        PCBDB.Save("C:\\newDatabase.xml");
    }
}

Here’s the database.xml:

<?xml version="1.0" encoding="utf-8"?>
<PCBDatabase>
  <SBE_PCB_Data PCBID="00001">
    <Creation ActionID="0002" User="DELLIOTTG:192.168.1.69" Date="2012-10-31T14:35:58" PCBID="00001">
      <PCBDrawing>00001a</PCBDrawing>
      <AssemblyDrawing>00001b</AssemblyDrawing>
      <Vendor>SBE</Vendor>
      <PONumber>00000</PONumber>
    </Creation>
    <Assignment ActionID="1295" User="RHO:192.168.1.6" Date="2012-12-13T08:59:31" PCBID="00001">
      <PCBDrawing>00002a</PCBDrawing>
      <AssemblyDrawing>00001c</AssemblyDrawing>
      <Vendor>SBE</Vendor>
      <PONumber>00001</PONumber>
    </Assignment>   
  </SBE_PCB_Data>
  <SBE_PCB_Data PCBID="00002">
    <Assignment ActionID="630c" User="DMUELLER:192.168.1.152" Date="2010-03-15T13:14:21" PCBID="00002">
      <SBEJobNumber>57380</SBEJobNumber>
    </Assignment>
  </SBE_PCB_Data>
</PCBDatabase>

And here’s the actionID.xml:

<?xml version="1.0"?>
<PCBDBActivityLog>
    <Assignment ActionID='8353' User='DMUELLER:192.168.1.134' Date='2011-01-27T15:38:25' PCBID='00001'>
        <SBEPN>41528E</SBEPN>
    </Assignment>
</PCBDBActivityLog>

The resultant file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<PCBDatabase>
  <SBE_PCB_Data PCBID="00001">
    <Creation ActionID="0002" User="DELLIOTTG:192.168.1.69" Date="2012-10-31T14:35:58" PCBID="00001">
      <PCBDrawing>00001a</PCBDrawing>
      <AssemblyDrawing>00001b</AssemblyDrawing>
      <Vendor>SBE</Vendor>
      <PONumber>00000</PONumber>
    </Creation>
    <Assignment ActionID="1295" User="RHO:192.168.1.6" Date="2012-12-13T08:59:31" PCBID="00001">
      <PCBDrawing>00002a</PCBDrawing>
      <AssemblyDrawing>00001c</AssemblyDrawing>
      <Vendor>SBE</Vendor>
      <PONumber>00001</PONumber>
    </Assignment>
    <Assignment ActionID='8353' User='DMUELLER:192.168.1.134' Date='2011-01-27T15:38:25' PCBID='00001'>
        <SBEPN>41528E</SBEPN>
    </Assignment>
  </SBE_PCB_Data>
  <SBE_PCB_Data PCBID="00002">
    <Assignment ActionID="630c" User="DMUELLER:192.168.1.152" Date="2010-03-15T13:14:21" PCBID="00002">
      <SBEJobNumber>57380</SBEJobNumber>
    </Assignment>
  </SBE_PCB_Data>
</PCBDatabase>

What am I missing or doing wrong?

  • 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-15T21:03:40+00:00Added an answer on June 15, 2026 at 9:03 pm

    Error is here:

    var actionXML = addAction.Root.Descendants("PCBDBActivityLog")` 
    

    You are trying to find <PCBDBActivityLog> elements under the document root. But this will return nothing, because <PCBDBActivityLog> element is a root of actionID.xml document. Replace this line with

    var actionXML = addAction.Descendants("PCBDBActivityLog");
    

    Or

    var actionXML = addAction.Root;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a application using PHP. Some example code is here. $url =
I have some code that I absolutely must implement using goto . For example,
I got problem with sending data in Android using httpPost. I found some example,
Trying to implement a sphere example code I found here on stackoverflow I have
I am using some code that I found for a drop down menu. It
I am using python, and suppose i had some code as below example.py import
I found some example of how to read the XML from an Excel spreadsheet
I'm trying to print Arabic in some PDF documents using the Java code found
I am trying to produce some example graphics using ggplot2, and one of the
I'm using some CSS properties that does not support in CSS 2.1. For example,

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.