Linq To Xml Syntax For Documents With Xml Namespace?

Aug 6, 2010

I'm trying to grasp the linq to xml 'inline query syntax' features of VB.Net First I tried with this simple xml file:

<?xml version="1.0" encoding="utf-8" ?>
<Root>
<Child Name="somename">

[code]....

This xml, when loaded in an XDocument, can be loaded and queried as follows:

Dim xdoc = XDocument.Load("sample.xml")
Console.WriteLine(xml.Root.<Child>.@Name)

Then I change the <Root> element in the sample xml file to:

<Root xmlns="http://SomeNamespace">

Now I can't seem to use the convenient 'Axis Properties' syntax anymore... I can only get it to work with the explicit XElement syntax:

Dim ns As XNamespace = "http://SomeNamespace"
' works, but I would like to use the same syntax as above...
Console.WriteLine(xdoc.Descendants(ns + "Child").First().Attribute("Name").Value)

View 1 Replies


ADVERTISEMENT

.net Namespace And Class Syntax?

Apr 7, 2011

I've added a new class1.vb file to my vb.net project containing:

Namespace MyFunc1
Public Class MyFunc2
Public Function Add(ByVal n1 As Int16, ByVal n2 As Int16) As Int16
return n1 + n2 ' Edited from: "Add = n1 + n2" (same thing)

[code]....

In form1.vb I thought I used to be able to call my functions with:

n = MyFunc1.Add(15, 16)

The error says "it's not a member".These also don't work as expected:

n = MyFunc2.Add(15, 16)
n = MyFunc1.MyFunc2.Add(15, 16)
n = Add(15, 16)

I thought for sure, this used to work:

n = MyFunc1.Add(15, 16)

View 2 Replies

System.Xml.Linq Namespace?

Jan 13, 2011

I have been given the task of calling a web service which returns an xml data feed which I am doing like so;

For Each r As DataRow in SomeDataTable
Dim msFeed As String = string.format("http://some-feed.com?param={0}", r!SOME_VAL)
Dim x

[code].....

View 4 Replies

Getting The Namespace System.xml.linq To Be Recognized?

Oct 26, 2008

I am using VS 2008 but am having problems getting the namespace system.xml.linq to be recognized. I am attempting to add the reference but I don't seem to be be allow to select it.System.XML.Linq is grayed out in the AddReference menu. What must I do to add this reference to my project?

View 3 Replies

Query For Namespace Dynamically Using Linq To XML?

Mar 5, 2012

I have 290 Group Policy Backup xml files which I need to enumerate in separate folders.

With each Group Policy backup xml file, I need to query the Policy settings.

Anyone who's looked at a Group Policy xml backup file before would know they're chock-a-block full of Namespace declarations.

I want to know, using Linq to XML, as I query each xml file, how can I dynamically query the XML the Namespace and then append the Namespace into the Linq query for the child nodes/values?[code]...

View 3 Replies

Read An XML Node In Namespace Using Linq

Feb 28, 2012

How do I work out what the namespace declaration is for the Extension node?I want to return all of the child nodes under: GPO->User->ExtensionData->Extension..[code]I get the following error: Sequence contains no elements..Also, the XML sample I have provided is only a small snippet, the ExtensionData->Extension nodes can be nested in different areas, so I was hoping to find the way of specifying the full path.

View 2 Replies

LINQ To XML: Suppressing Redundant Namespace Attribute In Child Nodes

Feb 25, 2010

If a node belongs to a namespace, it's children by default belong to the same namespace. So there's no need to provide an xmlns attribute on each child, which is good. However. If I create two nodes like this:

[Code]...

View 1 Replies

Using LINQ To XML With Global Namespace - Xmlns Is Added To Each Non-data Element?

Jan 14, 2010

I have to create an xml doc for a vendor who specifically states they must have their xml as follows:

<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<WMWROOT xmlns="http://www.blahblah.com/BLAH/Interface">
<WMWDATA>[code].......

I cannot find a way to get LINQ to spit out xml the way they want. Question is, can LINQ do it or do I need to resort to hardcoding the xml the old way before LINQ to XML?

View 5 Replies

Linq Syntax For .net?

Jul 14, 2009

tell me the equivalent syntax for the following code in VB.net?

Static Class TestList
{
static void Main()
{

[code].....

View 3 Replies

C# - Triple Dot Syntax For Linq To Xml

May 4, 2011

I ran into this answer which had a triple dot syntax in VB.NET that I have never seen before. The query looks like this

[Code]...

View 3 Replies

Differences In LINQ Syntax Between .Net And C#?

Jun 29, 2011

After I have programmed several projects in VB.Net I to my surprise discovered that there are some more than subtle differences between C# and VB.NET LINQ usage.For example, if we want to group elements by multiple properties (columns) we need to create a new anonymous type explicitly:

var procs = from c in Process.GetProcesses()
group c by new {c.BasePriority, c.Id} into d
select d;

whereas in VB.NET more straightforward syntax will already do:

Dim b = From c In Process.GetProcesses()
Group c By c.BasePriority, c.Id Into Group
Select Group

So, one does not need to create a type with "new" here. What are the other differences? good comparison between the LINQ syntax in C# and VB.NET?

View 2 Replies

Exclusionary Set Syntax With Linq, VB

May 5, 2009

I'd like to do a subtraction of sets based on criteria. A pseudo-query would look like:

select table1.columnn1
,table1.column2
from table1, table2

[Code]....

I can make it to about here:

dim list = From tbl1 In table1 Where tt.column1 ...

View 1 Replies

Linq Syntax In Program?

May 28, 2009

What I really want is to select these two tables in to an anon type like in Scott Gu's blog: here However, I would settle for this created type "ActiveLots" I am joining two tables together and want to be able to reference columns from each in my result set. [code]...

View 1 Replies

LINQ To XML Syntax For XML Element With Attributes?

May 13, 2009

I'm a bit of a LINQ newbie and I was having some trouble with the following. I'm trying to perform a query using LINQ on an XML file and store the results in a list of DataClass objects that match the XML.I've got an XML file that is defined like this:

<NewDataSet>
<NewDataTable>
<Field>Accepted ASNs</Field>
<Val>59</Val>[code]....

I have created a Data class to support this XML format. What I would like to do is create a LINQ Query to grab these 3 records and store them into a List of my DataClass. In order to support multiple Order elements, I have my class defined with a generic list of "Order" structs... It looks like this:

Public Class ASNData
Private _field As String
Private _value As String[code].....

how to grab the 3 order elements and store them into my list of Order structs.

View 4 Replies

LINQ To XML Syntax And Class Objects In .net?

Dec 10, 2010

I have the following XML file

<Test>
<Modules>
<Module Name= "Test1">
<QueueName Name="Test1Active1" Active="True"></QueueName>
<QueueName Name="Test1Active2" Active="True"></QueueName>

[Code]...

View 1 Replies

Syntax Trouble Building Xml From Linq

Jan 24, 2012

I am building an xml file with the help of Linq queries and I'm not sure why the code below doesn't work.[code]

View 1 Replies

VB Syntax For LINQ Query That Creates A New Set?

Dec 3, 2009

I am trying to AVERAGE 6 different fields on a DataTable, but without grouping. Just the AVERAGE. I have found a couple of examples in C#, but can't find any examples for how to do this in VB.Here is what I have so far:

Dim query = From dtRow In dtIn.AsEnumerable _
Where dtRow.Field(Of String)("FOLLOWUP") = "Alert" _
Select New With { _
.Brand_Functional_Avg = XXX.Average(Function(f) f("Brand_Functional")), _
.Brand_Personal_Avg = XXX.Average(Function(f) f("Brand_Personal")) _
}

What should I use for XXX? I tried all of the options that I could think of and nothing is compiling.

Trust me, if I could write this in C#, I would, but the project requires VB.

View 1 Replies

Linq Expression Chain Syntax For In Query?

Feb 25, 2011

I have a query that I cannot seem to replicate in expression method chain syntax. I have two tables "User" and "UserPayment". User and UserPayment have a one to many relation i.e. One User can have many UserPayments.

View 1 Replies

Syntax For Order By Clause In Linq To Sql That Has Select New With

May 25, 2011

I have a LINQ to sql statement that joins 2 tables. I would like to add a order by clause on one of the columns. However the order by clause does not seem to take effect at all. right syntax in VB.net to achieve order by in the following:

Dim query = From dtIt In dbsomecontext.mytable
Join dtIl In dbsomecontext.anothertable On dtIt.ItemID Equals dtIl.ItemID
Where dtIl.IsAvailable = True
Order By dtIt.manufacturer

[Code]...

View 2 Replies

.net - Proper Syntax For LINQ Query Selecting Only Certain Columns?

Sep 13, 2011

What is the proper syntax for this:

Dim qry As <??> = From f In dirInfo.GetFiles("*.QBW") Select File = f.FullName, Include = True
Dim dt As DataTable = qry.CopyToDataTable()

I tried as "IEnumerable(Of DataRow)" but that didn't work. At runtime it said:

Unable to cast object of type
'WhereSelectArrayIterator2[System.IO.FileInfo,VB$AnonymousType_02[System.String,System.Boolean]]'
to type
'System.Collections.Generic.IEnumerable`1[System.Data.DataRow]'.

View 5 Replies

LINQ - Syntax - Snippet Code In VB - Receiving An Error

Jul 14, 2009

I've been trying to write this snippet of code in VB, can anyone see what is wrong with it? I am recieving an error on line 5.

Dim a1 = From rows In db.tPDMLinkUsages _
Where (rows.ACCESSDATE >= DateTime.Today.AddDays(-90)) _
Select New With _
{ _

[CODE]...

View 5 Replies

What's Equivalent Syntax For Anonymous Types In A LINQ Statement

Jun 29, 2010

I'm trying to translate some C# LINQ code into VB.NET and am stuck on how to declare an anonymous type in VB.NET.[code]How do you translate C#'s new { ... } syntax into VB.NET?

View 2 Replies

Get The Page Documents Counts For Documents Stored As Tif Files

Feb 2, 2010

I've been asked to get the page counts for documents stored as tif files. What I have now is looping through our third party software to open them and then get the page count. I can't stop the image from flashing and it is very slow. Does anyone know of a way to loop through them quickly and can the page counts (one image can have many documents)?

View 5 Replies

.net - The System.Linq.Dynamic Namespace - Visual Studio Does Not Recognize In The Project Files The System.XXX References

Aug 11, 2011

I would use the System.Linq.Dynamic. I added the specified Dynamic.vb file, that starts like this:

[Code]...

to my (VB.NET)solution. Now Visual Studio does not recognize anymore in the project files the System.XXX references, proposing me to change them to Global.System.XXX

View 1 Replies

Adding Namespace Attribute To XElement - Prevent Blank/empty Namespace On Child Elements?

Mar 17, 2011

I need to read an xml document from a database record into an XDocument object in order for it to be deserialized. So that the deserialization will work, I need to apply a specific namespace to each of the level 1 elements. So XML looks a bit like this:

[Code]...

How do I prevent the blank/empty namespace being added to each child element of the element to which the required namespace has been applied?

View 1 Replies

ERROR : 'Namespace' Can Occur Only At File Or Namespace Level

Jan 29, 2012

Imports System.Windows.Forms

ERROR : 'Namespace' can occur only at file or namespace level

View 5 Replies

Type Or Namespace Name 'Messaging' Does Not Exist In Namespace 'System

Apr 10, 2010

The type or namespace name 'Messaging' does not exist in the namespace 'System' (are you missing an assembly reference?)

View 2 Replies

System Namespace Conflict With Sibling Namespace

Nov 16, 2011

This class is located in the namespace Acme.Infrastructure.Interface.A class with the same name EventArgs exists in the System namespace.In another project in my solution I have a class Acme.BusinessModules.MyModule.MyClass.When attempting to use the EventArgs class I have to fully qualify the class name or the compiler thinks I am using the System.EventArgs class.My understanding of namespace resolution was that the compiler would first look for the class in the current namespace, and then its parents. It seems that the compiler checks in System before it checks in sibling namespaces. Is it correct that System is checked before the sibling? Or is this behaviour caused by other issues (Imports order?)?

View 1 Replies

'Namespace' Statement Must End With A Matching 'End Namespace'?

Dec 8, 2011

I am getting this error,here is my code.

Public Class Sample2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click

[Code]....

View 4 Replies

Syntax/Command Trying To Implement Syntax Highlighting In RichTextBox?

Oct 12, 2011

I am having an issue trying to figure this out. I am writing a script editor that uses tabs (a tab control) and I want to implement syntax highlighting. My issue is that every sample I can find on syntax highlighting uses

Private Sub RichTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved