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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:19:40+00:00 2026-05-31T01:19:40+00:00

I have the following XML sample which I need to parse in order to

  • 0

I have the following XML sample which I need to parse in order to extract parameters:

    <?xml version="1.0" encoding="UTF-8"?>
<bulkCmConfigDataFile xmlns:un="utranNrm.xsd"  xmlns:xn="genericNrm.xsd" xmlns:gn="geranNrm.xsd"  xmlns="configData.xsd" 
 xmlns:es="Vendor1SpecificAttributes.1.0.xsd">
    <fileHeader fileFormatVersion="1.0" vendorName="Vendor1"/>
    <configData dnPrefix="Undefined">
        <xn:SubNetwork id="ONRM_ROOT_MO_R">
            <xn:SubNetwork id="RNC0001">
                <xn:MeContext id="BLABLA">
                </xn:MeContext>
                <xn:MeContext id="MACHIN">
                </xn:MeContext>
                <xn:MeContext id="RNC0001">
                    <xn:VsDataContainer id="RNC0001">
                    </xn:VsDataContainer>
                    <xn:ManagedElement id="1">
                        <un:RncFunction id="1">
                            <un:UtranCell id="111111A">
                                <un:attributes>
                                    <un:uarfcnUl>9800</un:uarfcnUl>
                                    <un:uarfcnDl>10700</un:uarfcnDl>
                                </un:attributes>
                                <xn:VsDataContainer id="111111A">
                                    <es:Position>
                                    <es:latitudeSign>1</es:latitudeSign>
                                    <es:latitude>3070727</es:latitude>
                                    <es:longitude>8786820</es:longitude>
                                    </es:Position>
                                </xn:VsDataContainer>
                                <xn:VsDataContainer id="1">
                                </xn:VsDataContainer>
                            </un:UtranCell>
                            <un:UtranCell id="111111B">
                                 <un:attributes>
                                    <un:uarfcnUl>9800</un:uarfcnUl>
                                    <un:uarfcnDl>10700</un:uarfcnDl>
                                </un:attributes>
                                <xn:VsDataContainer id="111111B">
                                    <es:Position>
                                    <es:latitudeSign>1</es:latitudeSign>
                                    <es:latitude>3070555</es:latitude>
                                    <es:longitude>8786666</es:longitude>
                                    </es:Position>
                                </xn:VsDataContainer>
                                <xn:VsDataContainer id="1">
                                </xn:VsDataContainer>
                            </un:UtranCell>
                        </un:RncFunction>
                    </xn:ManagedElement>
                </xn:MeContext>
            </xn:SubNetwork>
        </xn:SubNetwork>
    </configData>
    <fileFooter dateTime="2011-11-28T08:38:45Z"/>
</bulkCmConfigDataFile>             

So far I’ve only been able to retrieve the first element by name for a given namespace:

XNamespace xn = "genericNrm.xsd";
XNamespace un = "utranNrm.xsd";
var test1 = xmldoc.Descendants(xn + "MeContext").FirstOrDefault();

which will only give me the first Element “MeContext” (in this example this will return the MeContext with id=BLABLA).

If I try the following instead

XNamespace xn = "genericNrm.xsd";
XNamespace un = "utranNrm.xsd";
var test1 = xmldoc.Descendants(xn + "MeContext");

test1 will be null …

1 – My first question is how do I retrieve a specific element using its “id” attribute (in this specific example I’m looking for the id=”RNC0001″). I tried many things coming from stackoverflow including the following:

XNamespace xn = "genericNrm.xsd";
IEnumerable<XElement> utrancells =
                            xmldoc.Root
                                    .Elements(xn + "MeContext")
                                    .Where(el => (string)el.Attribute("id") == "RNC0001");

which only returns null values.

2 – The second problem is how to retrieve a collection of elements from the <xn:MeContext id="RNC0001"></xn:MeContext> ?
I would like to get all the <un:UtranCell id="XXXXX"></un:UtranCell> (and content) in a collection so I can extract data from each of them (each represent a different entity). For instance I need to retrieve

<es:latitude>3070555</es:latitude>
<es:longitude>8786666</es:longitude>

from each <un:UtranCell id="XXXXX"></un:UtranCell>

For this I tried (as a test):

XNamespace un = "utranNrm.xsd";
var test3 = xmldoc.Elements(un + "UtranCell");
var test4 = test1.Elements(un + "UtranCell");

and again it returns only null values …

Edit for Daniel: The real code is:

public void parseFile()
{
    XNamespace xn = "genericNrm.xsd";
    XNamespace un = "utranNrm.xsd";
    XNamespace cd = "configData.xsd";

    var test1 = xmldoc.Descendants(xn + "MeContext").FirstOrDefault();
    var test1bis = xmldoc.Descendants(xn + "MeContext");
}

This gives me:
test1 = <xn:MeContext id="BLABLA" xmlns:xn="genericNrm.xsd"></xn:MeContext>

test1bis = {System.Xml.Linq.XContainer.GetDescendants} | name = null

  • 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-05-31T01:19:42+00:00Added an answer on May 31, 2026 at 1:19 am

    The problem in both cases is that you are using Elements instead of Descendants. The difference is that Elements only returns those elements that are immediate children – i.e. one level deep, whereas Descendants searches the entire subtree. Try this instead:

    IEnumerable<XElement> utrancells =
        xmldoc.Root
              .Descendants(xn + "MeContext")
              .Where(el => (string)el.Attribute("id") == "RNC0001");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an app.config file, which contains the following <?xml version=1.0 encoding=utf-8 ?> <configuration>
I have the following XML <?xml version=1.0?> <FileHeader xmlns=urn:schemas-ncr-com:ECPIX:CXF:FileStructure:020001 VersionNumber=020001 TestFileIndicator=P CreationDate=13012009 CreationTime=172852 FileID=0000000001
I have 50000 XML records like this in the database: <?xml version=1.0 encoding=UTF-8?> <root>
I have the following sample XML structure: <SavingAccounts> <SavingAccount> <ServiceOnline>yes</ServiceOnline> <ServiceViaPhone>no</ServiceViaPhone> </SavingAccount> <SavingAccount> <ServiceOnline>no</ServiceOnline>
I have a simple xml document that looks like the following snippet. I need
I have the following XML structure: <?xml version=1.0 ?> <course xml:lang=nl> <body> <item id=787900813228567
I have the following xml I'd like to deserialize into a class <?xml version=1.0
I have the following xml sample: <items> <item> <item_id>1</item_id> <item_name>item 1</item_name> <group_id>1</group_id> <group_name>group 1</group_name>
I have a large xml file (approx. 10 MB) in following simple structure: <Errors>
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008

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.