473,657 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

retrieving distinct attributes from xml doc

In the xml document below, I would like to retrieve the distinct
attributes for the element '<Bal>'. However, I haven't had any
success. Here is what I have so far:

<TRANS>

<TRAN TRAN_DESC_CD="A CRT" TRAN_DESC="Actu al Rate">

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 11-01" />

</BAL>

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 13-01" />

</BAL>

<BAL BAL_FLD_NUM="2" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 112-01" />

</BAL>

<BAL BAL_FLD_NUM="6" BAL_FLD_DSCR="A ctual Dispersion Amount">

<SUBDEAL SUB_Deal_ID="02 342-01" />

</BAL>

</TRAN>

</TRANS>

IEnumerable<XAt tributeICOA =

(from ddList in GxmlCOA.Descend ants("BAL").Att ributes()

select ddList).Distinc t();

So the distinct bal fields should be:

1) Text = "Actual Rate Amount"

Val = 3

2) Text = "Actual Rate Amount"

Val = 2

3) Text = "Actual Dispersion Amount"

Val = 6

Unfortunately, the LINQ query isn't working.
Sep 12 '08 #1
2 4315
Test.Xml is A copy of yours

XmlDocument oXml = new XmlDocument();
oXml.Load("d:\\ temp\\test.xml" );
//get attribut
XmlNode testnode =
oXml.SelectSing leNode("TRANS/TRAN/BAL/SUBDEAL[@SUB_Deal_ID='0 0112-01']");
if (testnode==null )
{
Console.WriteLi ne("Not Found");
}
else
{

Console.WriteLi ne(testnode.Att ributes[0].Value);
}
//if u want all of the tran nodes TRANS being your root
XmlNode TranNodes = oXml.SelectSing leNode("TRANS/TRAN");
for (int x = 0; x < TranNodes.Child Nodes.Count; x++)
{
//all attributes
XmlNode node = TranNodes.Child Nodes[x];
Console.WriteLi ne(node.Name);
if (node.Attribute s.Count 0)
{
for (int y = 0; y < node.Attributes .Count; y++)
{
Console.WriteLi ne(node.Attribu tes[y].Name.ToString( )
+ " " + node.Attributes[y].Value.ToString ());
}
}

}
Dave

"rds80" <sh*********@gm ail.comwrote in message
news:6c******** *************** ***********@b1g 2000hsg.googleg roups.com...
In the xml document below, I would like to retrieve the distinct
attributes for the element '<Bal>'. However, I haven't had any
success. Here is what I have so far:

<TRANS>

<TRAN TRAN_DESC_CD="A CRT" TRAN_DESC="Actu al Rate">

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 11-01" />

</BAL>

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 13-01" />

</BAL>

<BAL BAL_FLD_NUM="2" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 112-01" />

</BAL>

<BAL BAL_FLD_NUM="6" BAL_FLD_DSCR="A ctual Dispersion Amount">

<SUBDEAL SUB_Deal_ID="02 342-01" />

</BAL>

</TRAN>

</TRANS>

IEnumerable<XAt tributeICOA =

(from ddList in GxmlCOA.Descend ants("BAL").Att ributes()

select ddList).Distinc t();

So the distinct bal fields should be:

1) Text = "Actual Rate Amount"

Val = 3

2) Text = "Actual Rate Amount"

Val = 2

3) Text = "Actual Dispersion Amount"

Val = 6

Unfortunately, the LINQ query isn't working.

Sep 12 '08 #2
Hi

You could create your own object, which overrides Equal and
GetHashCode. Something like:

using System;
using System.Linq;
using System.Xml.Linq ;
using System.Collecti ons.Generic;

public class DistinctAttr {
public static void Main(string[] args)
{
XElement el = XElement.Load(" DistinctAttr.xm l");
var attrs =
el.Descendants( "BAL").
Select(e =>
new MyAttr
{
Num = e.Attribute("BA L_FLD_NUM").Val ue,
Dscr = e.Attribute("BA L_FLD_DSCR").Va lue
}
).Distinct();
foreach(var at in attrs)
{
Console.WriteLi ne("num: {0}, dscr: {1}", at.Num, at.Dscr);
}
}

class MyAttr
{
private string _num, _dscr;
public override bool Equals(object obj)
{
if(obj == null || !(obj is MyAttr)) return false;
MyAttr at = (MyAttr) obj;
return this._num == at.Num && this._dscr == at.Dscr;
}

public override int GetHashCode()
{
return (int) (_num.GetHashCo de() + _dscr.GetHashCo de());
}

public string Num {get{return this._num;} set{this._num = value;}}
public string Dscr {get{return this._dscr;} set{this._dscr =
value;}}
}
}

Regards
Steve

On Sep 12, 5:10*pm, rds80 <shah.rip...@gm ail.comwrote:
In the xml document below, I would like to retrieve the distinct
attributes for the element '<Bal>'. *However, I haven't had any
success. Here is what I have so far:

<TRANS>

<TRAN TRAN_DESC_CD="A CRT" TRAN_DESC="Actu al Rate">

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 11-01" />

</BAL>

<BAL BAL_FLD_NUM="3" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 13-01" />

</BAL>

<BAL BAL_FLD_NUM="2" BAL_FLD_DSCR="A ctual Rate Amount">

<SUBDEAL SUB_Deal_ID="00 112-01" />

</BAL>

<BAL BAL_FLD_NUM="6" BAL_FLD_DSCR="A ctual Dispersion Amount">

<SUBDEAL SUB_Deal_ID="02 342-01" />

</BAL>

</TRAN>

</TRANS>

IEnumerable<XAt tributeICOA =

(from ddList in GxmlCOA.Descend ants("BAL").Att ributes()

select ddList).Distinc t();

So the distinct bal fields should be:

1) Text = "Actual Rate Amount"

Val = 3

2) Text = "Actual Rate Amount"

Val = 2

3) Text = "Actual Dispersion Amount"

Val = 6

Unfortunately, the LINQ query isn't working.
Sep 14 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6108
by: Florian | last post by:
Hi, I have a table that contains log data, usually around a million records. The table has about 10 columns with various attributes of the logged data, nothing special. We're using SQL Server 2000. Some of the columns (for example "category") have duplicate values throughout the records. We have a web page that queries the table to show all the unique columns, for example:
0
1074
by: Audun | last post by:
Hi I've been trying to read the following attributes from Active Directory: networkAddress and netbootGUID. (Using c# and the DirectoryEntry class.) Tried to search, and explicitt load these attributes into the cache, and I've tried to bind directly to the computer object, and refresh these attributes in the cache. The computer account I'm using as test account has values in these attributes, but when I list properties in my cache they...
1
2477
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the only way to find out the current state of a particular combination of attributes is to "select distinct on (id, ...) ... order by date desc". In the examples below, I've taken real output from psql and done a global search/replace on various...
4
5290
by: Iain | last post by:
I've an xml document that looks a bit like this <Vendors> <Vendor Stationery="Fred" /> <Vendor Stationery="bert" /> <Vendor Stationery="bert" /> </Vendors> I want to extract a list of the distinct values of Stationery. I've found some things on the web that suggest XPath statements to do this (in XSLT),
9
10863
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my table:- ID Ref Name DATE 1 AAA Joe 1/2 2 BBB Ken 1/2 3 AAA Len 6/3
3
3186
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what the set piece of the Name property gets compiled to, which I am getting from the stack trace, then the attributes are not returned. For example, Class Person has a property called "Name" which has a custom attribute decorating it. Inside the set...
4
6141
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
1
3336
by: Damien | last post by:
I have seen examples of selecting distinct elements by name, but my issue is that I need to get distinct attributes by name. My XML looks like: <root> <file> <rows> <row att1="1" /> <row att2="2" /> <row att1="1" att2="2" />
0
3377
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.