Wpf - Parse XML With Linq?
Jan 21, 2011
I have the following XML document which I would like to parse into a DataSet.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Response Status="OK">
<Item>
<Field Name="ID">767147519</Field>
[code]....
EDIT:Following one of the answers below, I have been attempting to implement an anonymous type in my Linq, however I keep encountering the error
Object reference not set to an instance of an object.
My updated code is as follows:
Dim name = From c In loaded.Descendants("Item") Select c Select sID = c.Element("Field").Attribute("Name").Value, sName = c.Attribute("ID").Value.FirstOrDefault
Dim Id As String = String.Empty
[code]....
I think this error means that the attribute ("ID") cannot be located, so I have attempted several variations of this with similar results.
View 12 Replies
ADVERTISEMENT
Mar 18, 2011
I've been using LINQ so much in the last couple of weeks that when I had to write a one line function to remove < and > from a string, I found that I had written it as a LINQ query: [code] My question is, is it better to do it with LINQ as above or with StringBuilder as I've always done, as below: [code] Both work, the second one is easier to read, but the first one is designed for executing queries against arrays and other enumerables.
View 2 Replies
Jun 8, 2012
I just want to parse simple expressions like IIF(FVAL(PFC) = TRUE, (IIF((ORGVAL(BAS, "2012/12/31") + ORGVAL(DA)) < 6500, (FVAL(BAS) + FVAL(DA)) * 12%, 780)), 0)`After parsing this I should be able to know what functions contains what parameters.
[Code]...
I'm stuck with .Net Framework 2.0, so no Linq or lambda expression goodies for me. Also I want to include the code in my custom library and not just reference it. Can anyone point me to some good library or code.
I just need to parse and not evaluate the expression and find what tokens are in use. After finding the tokens I need to change the expression string before parsing, like if the function ORGVAL is used then the parameter passed has has to be prefixed by an underscore. Like ORGVAL(BAS) will transform to ORGVAL(_BAS). Some functions can have tow parameters like ORGVAL(BAS, "2012/12/31") and this will transform to ORGVAL(_BAS, "2012/12/31")
NOTE: IF THERE ARE OTHER WAYS OF DOING IT PLEASE LET ME KNOW. I WOULD LOVE TO AVOID A PARSER AND LEXER.
View 3 Replies
Jul 14, 2011
given this function:
Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _
[Code]....
instead of what I expected:
Select count(*) from remitline where lastname = "smith"
What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1
View 1 Replies
Aug 6, 2009
if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?
View 1 Replies
Apr 20, 2011
I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:
Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....
Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:
For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....
View 1 Replies
Sep 10, 2009
Example-I have a person class
Public Class Person
Private _fname As String
Public Property Fname() As String
[Code]...
View 2 Replies
Mar 31, 2011
Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext
bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _
[Code]...
with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."
View 1 Replies
Jan 27, 2011
We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)
Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _
[code]....
View 1 Replies
Feb 28, 2012
The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.
Here's what I have:
<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)
[code]....
I want my usage to look something like this:
Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)
I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.
View 2 Replies
Jun 27, 2012
How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net
[Code]...
View 2 Replies
Aug 31, 2011
How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?
[Code]...
I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.
View 1 Replies
Oct 21, 2009
How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:
Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo
[code]....
View 1 Replies
Apr 20, 2010
I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).
It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.
For example... I write this:
[CODE]....................
Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.
So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.
View 2 Replies
Jul 29, 2010
I'm still relatively new to parsing xml documents into SQL. I am trying to parse one node out of an xml document.[code]...
View 12 Replies
Sep 29, 2009
What's the easiest way in VB.NET to parse this XML? Here's an example of the full source:View Source XML I believe that the XML can be read directly into a class structure that matches the XML's structure.Let's take a bit of the XML from the above example,
<?xml version="1.0" encoding="UTF-8" ?>
- <kml xmlns="http://earth.google.com/kml/2.0">
- <Response>
[code]....
How do I handle nested collections, for example, the Placemark collection in this example?
View 2 Replies
Sep 17, 2011
I have an app that the user selects information and it writes to an XML file. The user can increase and decrease the information in the XML file so it is dynamic. The other app reads the xml file and uses it to complete tasks. Since the XML is dynamic my code needs to account for that. Right now I have only allowed the XML to have up to four values in a certain node, I would like to allow more but I will need to increase the Select Case function.[code]
View 8 Replies
May 5, 2011
I am making a change to an existing process. Currently the csv file (which can have embedded "," with the field in quotes), is being passed to my module as a IO.StreamReader, pStreamReader.
[Code]...
View 2 Replies
Oct 31, 2010
parsing text that i have loaded in to my textbox Using ofd1 As New OpenFileDialog ofd1.InitialDirectory = "F:"
If ofd1.ShowDialog = DialogResult.OK Then RichTextBox2.Text = My.Computer.FileSystem.ReadAllText(ofd1.FileName)
End If
End Using
View 5 Replies
Apr 6, 2010
create a function that parses the input "4+7-4/4*4=" from instr into an array named tokens(1000), as string, and returns the number of arrays, or perhaps a negative number if there is an error in the input.
Dim tokens(1000) As String
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
[code].....
View 1 Replies
Nov 1, 2009
I have XML data like this:[code]I would like to return the name of the places. How may I extract this data using Visual Basic?
View 3 Replies
Jul 27, 2011
I may be getting in way over my head, but here it goes. I am developing a small application for use on a helpdesk. The application will be installed on the client pc's and will be used primarily by the end user to assist the technician on the phone if the user's pc is offline or inaccessible. One part of the application gives the user their IP address, DNS address, DHCP address, and gateway address. I have it to where it will put all of those in the corresponding fields inside a form, but it does not work correctly outside of a domain. Outside of a domain it only gives the IP address. I am sure it is probably how I coded it, but I cannot think of any other way to get that info in a user friendly way. Is there a way to parse a command prompt command to specific fields inside of a form such as the command ipconfig /all?
View 3 Replies
May 5, 2011
I am making a change to an existing process. Currently the csv file (which can have embedded "," with the field in quotes), i being passed as an
IO.StreamReader parameter pStreamReader.
dim vLine as string = pStreamReader.ReadLine
dim vFields () as String = vLine.Split(","c)
Well ... obviously the split does not work with embedded commas in a field. Looked at TextFieldParser, but it is in the FileIO class and the module is passed a IO.StreamReader. Can it work?
Or how abour a RegEx? Does anyone have any suggestions? I have look around on the internet and it seems like a common questions with a bunch of wild goose chases.
View 10 Replies
May 5, 2011
I am making a change to an existing process. Currently the csv file (which can have embedded "," with the field in quotes), i being passed as an IO.StreamReader, pStreamReader to my module.
The code reads ....
dim vLine as string = pStreamReader.ReadLine
dim vFields () as String = vLine.Split(","c)
Well ... obviously the split does not work with embedded commas in a field. Looked at TextFieldParser, but it is in the FileIO class and the module is passed a IO.StreamReader.
Or how abour a RegEx? I have look around on the internet and it seems like a common questions with a bunch of wild goose chases.
View 1 Replies
Jun 12, 2012
Here is a snippet of an XML file that I need to read with VB.NET[code]...
I am familiar with creating a new XmlDocument and using the Load method to read the file. I know how to get a collection of child nodes and loop through them to get elements and attributes. But in this case, I need to extract all of the data between the two "verse" tags (the starting one with the "sID" attribute and the ending one with the "eID" attribute), including the tags and the data in between as one continuous string. I can loop on the nodes, but I only get the "w" nodes and one final "#text" node for the period, but I don't know how to get the spaces and punctuation between the "w" tags.
View 3 Replies
Dec 7, 2010
I have a comma delimited text file with the U.S. States and their respective state bird listed in the following format.
"ALABAMA", "YELLOWHAMMER"
"ARKANSAS","...
"...
What im trying to do is parse the rows and send the parsed data to different comboboxes. I have a combobox for states and one for birds.I can load the file into the first combo box but im not sure how to parse and send the second column to the second combobox. here is what i have so far.
[Code]...
View 10 Replies
Jul 29, 2010
How can I actually send a string or another variable on the run to another running .net app? I searched google and found nothing really,
View 3 Replies
Apr 10, 2009
I have a text file that is in a comma separated format, delimited by " on most fields. I am trying to get that into something I can enumerate through (Generic Collection, for example). I don't have control over how the file is output nor the character it uses for the delimiter.
[Code]...
View 12 Replies
Apr 15, 2012
how to convert rss feeds to datagrid in this fomat
<Row>
<Cell><Data ss:Type="String">Symbol</Data></Cell>
<Cell><Data ss:Type="String">Close</Data></Cell>
<Cell><Data ss:Type="String">Prev</Data></Cell>
[code]....
the values in the first <row> </row> of data are the column headings for the corresponding cells in the other <row> </row>considering that I can work with xml in the other format this is quite strange so any help will be needed.
View 3 Replies
Aug 13, 2010
I am using mysql and I have installed the connector... here is a sample of my code. so far I can sucessfully connect to the db, but i am trying to learn how to parse sql commands to the db. for example in this snippet, i wanted to add to the testing table, an entry consisting of Fname and Lname.... It is not working... what should i be doing different ??
Imports
MySql.Data.MySqlClient
Imports
[Code].......
View 2 Replies