Avatar of tia_kamakshi
tia_kamakshi
Flag for United Arab Emirates asked on

Getting attributes value from XML using a C# 2.0 function

Hi Experts,
I am using C# 2.0 and I have below xml format (it is just a sample) and got loaded in  XPathDocument xmlData;

<?xml version="1.0"?>
<sitedata>
<resources>
<WorldwideSites>Worldwide sites</WorldwideSites>
<PublishedDate>20120507163835</PublishedDate>
</resources>
<region code="global" title="Global">
<site defaultLanguage="en" id="tcm:0-233-1" url="/english" countryCode="" title="" order="1">
<language code="en" pubId="tcm:0-233-1" countrylang="en-GB">English</language>
</site>
</region>
<region code="NSAM" title="North &amp; South America">
<site defaultLanguage="es" id="tcm:0-520-1" url="/ar/spanish" countryCode="AR" title="Argentina">
<language code="es" pubId="tcm:0-520-1" countrylang="es-AR" >Español</language>
<language code="en" pubId="tcm:0-447-1" countrylang="en-AR" >English</language>
</site>
</region>
<region code="EU" title="Europe">
<site defaultLanguage="de" id="tcm:0-336-1" url="/at/german" countryCode="AT" title="Austria">
<language code="de" pubId="tcm:0-336-1" countrylang="de-AT" >Deutsch</language>
<language code="en" pubId="tcm:0-337-1" countrylang="en-AT" >English</language>
</site>
</region>
</sitedata>

Open in new window


Now I want to create a C# 2.0 function which will take this XML as input and will return back a multidimensional array or arraylist

ArrayList xmldata = new ArrayList();
xmldata[0][0] will be ["233"]["en-GB"] //a middle part of pubId attribute
xmldata[1][1] will be ["520"]["es-AR"] //attribute value of countrylang
..
..
and so on

Open in new window


Or suggest the best approach

Please suggest!!

Thanks.
C#XML.NET Programming

Avatar of undefined
Last Comment
tia_kamakshi

8/22/2022 - Mon
Bardobrave

What's exactly your problem?

Don't seem very difficult to loop through region tags, getting id attribute from site tags, splitting it through ('-') and getting countryLang attribute on language tags.

Are you having difficulties with something in particular?
tia_kamakshi

ASKER
@Bardobrave...thanks, can you please provide me some code sample for above problem and what should I return back .

Please suggest!!
ASKER CERTIFIED SOLUTION
tia_kamakshi

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Bardobrave

It seems fine... does it work?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
tia_kamakshi

ASKER
@Bardobrave, it is working fine any optimization i need to do for better performance
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
tia_kamakshi

ASKER
As suggested by expert still there were something to find in xml object for other object