Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
September 20th, 2008, 12:01 AM
|
#1 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
need help with all you linq experts...
got a simple xml files: Code: <?xml version="1.0" encoding="utf-8" ?>
<root>
<Package id="1" name="Jason1">
<nuclide rsic="100" nucname="co60"></nuclide>
<nuclide rsic="110" nucname="co70"></nuclide>
</Package>
<Package id="2" name="Jason2">
<nuclide rsic="200" nucname="do60"></nuclide>
<nuclide rsic="210" nucname="do70"></nuclide>
</Package>
</root> as you can see nuclide is a list of nuclides inside a package...
so i have a package class which contains a list of nuclides...
I want to populate my object from the xml file but i am having trouble with the syntax of loading the list....
This is what i have... I tried a whole bunch of other thing that didnt work...this is the ball park i am in right now: Code: Dim xml As New XmlDocument
xml.Load("Test.xml")
Select New MyNewClass() With {._iID = CType(CType(myXML, XmlElement).GetAttribute("id"), Int32), _
._strName = CType(myXML, XmlElement).GetAttribute("name").ToString} _
.AddNuc = (From myxml2 In xml.ChildNodes(0) Select New Nuclides With {._iID = CType(CType(myxml2, XmlElement).Attributes("rsic").Value, Int32)}).ToArray
i was able to load everything, but it would only load the first nuclide. I can't get it too loop around. It looks like i need another select statement but i can't figure out the syntax. havent found anything on the web yet that resembles this issue.
Thanks in advance |
| |
September 20th, 2008, 12:23 AM
|
#2 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
incase anyone wants to know the answer.... Code: Dim SQL = From myXML In xml.SelectNodes("root/Package") _
Select New MyNewClass() With {._iID = CType(CType(myXML, XmlElement).GetAttribute("id"), Int32), _
._strName = CType(myXML, XmlElement).GetAttribute("name").ToString, _
.AddNuc = (From NucXML In CType(myXML, XmlElement) _
Select New Nuclides With {._iID = CType(CType(NucXML, XmlElement).GetAttribute("rsic"), Int32), _
._strName = CType(NucXML, XmlElement).GetAttribute("nucname").ToString})} I understand the benefits of being able to query off of objects...That is pretty beneficial....
Not really sure how great the Linq to xml or Linq to SQL is...i would rather do it myself and have more control over it.
What is everyones thoughts on Linq??? |
| |
September 20th, 2008, 01:20 AM
|
#3 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 20,454
|
i'm no expert in it, but friend of mine that is into C# is really liking it
I have no clue on XML stuff, so I can't comment on how it is for that type of information.
I've been stuck in vbs land for awhile, so having something that has more control over text manipulation is always a good thing, and linq provides that w/o full iteration over the text |
| |
September 20th, 2008, 01:29 AM
|
#4 (permalink)
| | Member
Join Date: Oct 2003
Posts: 247
|
some features are really cool. Added a a new object with line 3 lines of code is awesome. The ability to query classes without having to write all the iterations yourself is helpful.
Ahhh vbs...I use to do alot of work in vbs...my last job was with actuaries. They love their excel spreadsheets! |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |