XElement And Namespaces [VB 2010]?

Dec 2, 2011

I have two XML files.

Consumers.xml
<consumers>
<consumer>consumer1</consumer>

[code].....

View 2 Replies


ADVERTISEMENT

Read Xml Files Which Contain Namespaces With Xelement?

Jun 9, 2011

I have the file xmlcontents.xml with the following content[code]....

View 4 Replies

Creating A Child Class Of XElement That Still Keeps A Reference To Original XElement And Preserves Tree Structure

Dec 20, 2010

I'm working with a class that inherits the XElement class.The new class is called MXElement.It adds some new functionality to it for navigating through the XML tree, as well as some more information regarding attributes, but that's not particularly important.My problem is that I have an XML Tree filled with XElement objects.However, when I create a new MXElement object from the XElement object before, it is just a copy of that object. This means that any changes that I make to this object will not effect the original tree.I suppose what I'm asking for is a way to build in the functionality for my MXElement class and keep references to the original XElement objects.If possible, I would really prefer to keep MXElement a child class instead of building a lot of extension methods for XElement.

View 1 Replies

XElement.Add(XElement) Automatically Adds Namespace To Child Node?

Nov 4, 2011

I am using XElement to manipulate my xml file: to find target node and then add child node to it. But now I have one problem. Let's say my xml file looks like this:

<Report xmlns="MY_NAMESPACE"
<Width>100</Width>
<Height>100</Height>

[Code].....

The second <ReportItem> is the newly-added one, but sadly this is not a valid file (my parser is complaining in the further processing of xml file). So how can I make this new item look exactly like the existing one, without any namespace? This has been driving me crazy. I spent a whole day to figure out that I need to add the curly brackets so that it will find the target node (it doesn't work like what the link above says that it adds and searches the default NS automatically), but now it adds something unnecessary?

View 1 Replies

Adding XElement As A Child Of An Existing XElement Linq?

Mar 6, 2012

I would like to add a XElement into an existing XElement as a child

Dim myDocument As New XDocument
myDocument.Declaration = New XDeclaration("1.0", "utf-8", "no")
myDocument.Add(New XComment("XComment"))

[Code]....

What is the best way? There will be at least one rule but there could be as many as 4 total.

View 4 Replies

Adding Xelement As A Sibling Of Xelement Without A Parent?

Oct 11, 2010

I'm trying figure out if this is possible. Basically, I need to create an XElement and then add one or more siblings to that XElement, but without a parent. I'll add that list of XElements to a Parent later, but need some flexibility in building this and other lists of XElements before doing so. Is this possible?

So I would have something like:

Public items As XElement = <ItemA>Something</ItemA>

And then I need to add an element so that the result looks like:

<ItemA>Something</ItemA>
<ItemB>Something Else</ItemB>

That result is what I need to pass around as a single object. I've messed arounnd with IEnumerable(Of XElement), but there is no .Add.

View 1 Replies

Conditional XElement Content / XElement Or XAttribute

Feb 15, 2011

I'm building XML based on some data pulled from a database, and thought to try building the XML with LINQ2XML. The data is coming from a few different places, so I've been building the XML by sections, based on what I have populated in DataTable objects. Using the XElements and XAttributes, I can get one or the other, but I was wondering if anyone had insight in how to make the determination of whether to use XElement or XAttribute at the point where the XML is being built.[code]So it's in that LINQ query that I need to determine if ValueToParse, for example, has a valid value (non-empty). If it does, then I can add the node and it's value. If it DOES NOT, I need to add that named node, but with an attribute of 'xsi:nil="true"',The caveats are that that there are some descendants which repeat over different parents (for example, there's an AddressDetails section which contains AddressDetail elements. These AddressDetail elements can contain 0 or 1 Contacts groups of Contact elements, so adding a node to the Contacts node isn't a straightforward option as it would be if there was only ONE Contacts element).I don't usually USE LINQ, but it SEEMED like a good idea at the time XD

View 1 Replies

VS 2010 - Importing Namespaces (List Of References)

Jan 2, 2012

I would like to import System.Data.OleDb to my list of references, but it won't let me, I can't find it on the list but it's obviously there cause I can type olede.oledbparameter.

My list shows
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.Services.Client
System.Data.SqlXml

I can't find System.Data.Oledb. Now, I did a "hack" job and got it added, but I couldn't figure out how to do it with the GUI. I edited the .proj file with notepad and added it manually.

How can I add it with the GUI?
Steps:
Clicked on Project
Clicked on Add Reference...
Clicked on .Net, Com, Projects
Couldn't find it on either of those lists.

View 3 Replies

VS 2010 - Automatically Adding Namespaces To Classes Within Folders

Jul 26, 2010

Is it possible to have visual studio 2010 automatically add namespaces to classes within folders just like c#?

View 1 Replies

C# - Get InnerText From XElement?

Mar 19, 2011

I have an XML file I need to parse, but only for the text, not the HTML. Here's an example of a node:

<highlights><![CDATA[<ul style="color:#000000;font-size:small;font-family:verdana,geneva,sans-serif"><li>Classy &amp; elegant purse hooks</li><li>Choose from various styles<br></li><li>Stable and reliable</li><li>Makes a great gift! </li></ul> ]]></highlights>

As you can see, the CDATA has HTML code in it, so when I do element.Value I also get the tags. Is there any simple way to get just the text?

View 2 Replies

How To Set An Empty XElement

Dec 22, 2009

Im trying to add a Xelement to an XElement. But when I tried to add this XElement to the empty XElement VB throws "Object reference not set to an instance of an object" The Bold line code throws the exception

here the sample code: Private Sub Button_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_OK.Click

[Code]...

View 3 Replies

XElement And An XPath Expression ?

Feb 1, 2010

I have an XElement and an XPath expression that selects a node from it. It works fine in the original program that I wrote it in but doesnt work if I paste it to another program. I've checked the references and import statements.

I think the problem might be that the original program had the code within the class of a wpf window while it was moved to a abstract class where it doesnt work.[code...]

View 1 Replies

Get Only Direct Descendants Of An XElement?

Aug 4, 2009

[code]...

In this case, children includes all the Parent elements and all of the Child elements. What's the best way to grab only the direct descendants of <Root>?

Should I write a LINQ query that selects elements where parent = <Root>? Or is there some built-in method I'm missing that can get this for me?

EDIT: I had some confusion between XElement.Elements and XElement.Descendants. As Ruben Bartelink pointed out, XElement.Elements will give me exactly what I was looking for.

View 4 Replies

Test To See When An Xelement Exists?

Mar 6, 2009

I'm reading an XML file that looks like this[cod]...

The resulting List(Of Vehicle) is then bound to an ASP.NET ListView control where the data is rendered. All goes well if all the desired nodes are present. For example, the Mileage node is conditional and is absent sometimes. Whenever the node isn't present I get a "Sequence contains no elements" error.

I've tried everything I know to get things working properly. Is there a way to test if an XElement exists?

View 1 Replies

Typecasting XElement To String?

Jun 11, 2009

I am trying to retrieve a value from an xml file via the XElement and pass it on to a function for further logic testing / et al but keep getting an eror: Here is the code I am using

dim path as string = "C:UsersPaulmyfile.xml"
dim doc as xelement =xelement.load(path)

'This is the line that i would like to convert i.e the sdr to string ? dim sdr = from d in doc.descendants("BOOKS") Select d.Value

when I pass the value sdr, I get an error 13 "Conversion from type "WhereSelectEnumerableIterator(Of XElement, String) to type string is not valid. I have also tried to pass it as an object but can not seem to be able to typecast it to string.

View 15 Replies

Use For Each Loop With A Where Clause For XElement?

Oct 5, 2010

I am tring to write a for each loop that loops through the descendants of an xml doc but only the ones that satisfy a criteria.[code]...

View 1 Replies

Xml - Reading Childelement To XElement In .NET?

Dec 22, 2011

I've been trying to read an XML-file using VB.NET and after some (see 2-3 hours) googling and reading I've headed in somewhat the right direction, however now I'm at a stop and I can't find any answers that makes any sense to me.

[Code]...

View 1 Replies

IEnumerable<XElement>.Value() Extension Method Available In .Net But Not C#?

Jun 5, 2012

In VB.Net you can easily get the text value of the first child element of an XElement like so:Dim sChildValue = xeParent.<MyChild>.Value()Of course that syntax is not supported in C#, but it produces the same IEnumerable(Of XElement) result as the Elements() method. So we can rewrite the above like so:

Dim sChildValue = xeParent.Elements("MyChild").Value()This Value() extension method is handy because often you are working with small XML documents and you just want the first node that matches. (One thing that annoys me about this method is that it seems to return Nothing/null if the IEnumerable list is empty due to the specified element not being found. To work around this I have created my own ValueOrBlank() method that returns an empty string in that situation instead.)

My problem is that I can't do the same thing in C#:var sChildValue = xeParent.Elements("MyChild").Value(); // won't compile, can't find Value() method

I checked my references/imports and they match the VB.Net project where the same call works. Fortunately I am able to use my custom ValueOrBlank() extension method to accomplish the same thing. But I'm curious as to what's missing in my C# project. I tried right-clicking on the Value() method call in Visual Studio and clicking "Go To Definition" to see if the Object Browser could tell me where the extension method is kept, but it just shows the System.String class. Does that mean this is one of those sneaky VB.Net-only features that the compiler itself supports, like the XML Axis < MyChild > syntax?

View 2 Replies

VS 2008 Read These Values From XML With XElement?

May 2, 2012

im having problems with reading these values from XML with XElement Im trying to get Each value between <month> and </month>

<Document>
<Element>
<status>1</status>
<data>

[code]....

View 2 Replies

.net - Convert Linq.Xelement To Stream For XMLTextReader?

Nov 16, 2010

I am producing an XML file in my unit test using

Public Sub rssParserTest
Dim Const rssUri as String = "rssTestFile.xml"
Dim xmlFile = <rss version="2.0">

[Code]...

I want to remove the unit test dependency on a physical file and use a stream instead but my efforts so far have come to nought. (Is this best practise?)I am using NMock2 for mocking if I should be doing something with that.

View 2 Replies

Loading A Xml Document From A File Built Use Linq.Xelement

Jan 11, 2012

I'm trying to load in a xml file that was build using another windows form, but when I try the xml document I get the following error: Name cannot begin with the '%' character, hexadecimal value 0x25. Line 10, position 13.[code]

View 3 Replies

XElement.Element.value Throws Null Reference Exception

Aug 10, 2011

Goal: Load a validated xml file in to memory, traverse through the document to create objects and load object properties with values in named xml tags.Problem: How do I deal with missing tags?Amplifying information: in this example, there are three values I'm looking for; name (mandatory), location (optional), comments(optional). I found the problem in prototyping the solution. My inital test was with an xml file wtih all fields present. It works fine as long as I don't have nanespace declarations in the root element. However, if I leave them in place I get a null reference exceptoin. The same thing occurs if I leave off an optional tag. It appears that if the Element I'm trying to get a value on doesn't exist within that element, a null reference exception is thrown.

Code:

Private Sub btnImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImport.Click
Dim xelement As XElement = xelement.Load(txtXMLfileLoc.Text)
Dim ICAOxs As IEnumerable(Of XElement) = xelement.Elements()

[code]....

View 5 Replies

XElement.Parse Unexpected End Of File. Elements Are Not Closed

Jun 10, 2011

I am trying to parse incoming data from a serial port that appears to be XML format but an exception is thrown when I switch from a simulated setup to the real deal.My program runs great in a simulated setup but when I try it out on the real device I get: XmlException was unhandled Unexpected end of file has occurred. The following elements are not closed: li840 line 1, position 9.The li840 tag is my root tag and the position never seems to get past 40. I've tried using a try catch block but in my in both my simulated and real setups my values are blank but the program will run without exceptions. Should I take my received data and put it into a file and then read from the file? or is there something else I can do to make this work properly? [code]

View 12 Replies

XML Literals Parsing - XElement.Parse(variable Containing Text)

Sep 4, 2009

If I have a text stored in db, file, resource does not matter:

<code><%= Integer.MaxValue %></code>

Is there a way to do this: Dim el As XElement = XElement.Parse({variable containing text above}) and to have it evaluate the expression Integer.MaxValue?

View 3 Replies

Asp.net - Using Namespaces With C#?

Nov 4, 2010

I'm just starting out learning C# this may be really simple but in VB i have these namespaces

<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Globalization" %>
<%@ import Namespace="System.Data.SqlClient" %>

How do I go about using those namespaces in C#?

I tried

namespace System.Data

and

using System.Data

but they didn't work

View 4 Replies

Storing SQL Strings In XML XElement Instead Of String To Preserve Line Breaks?

Jun 22, 2010

When it comes to storing SQL in code, most people use strings:Dim strSql As String = "Select Foo, Bar From FooBarTable Where Something = @Something"The problem is, when you have very long SQL strings, reading them in code becomes difficult. You can usually split the strings up like this:

Dim strSql As String = "Select Foo, Bar From FooBarTable " & _
"Where Something = @Something"
This causes a number of problems:

[code].....

View 2 Replies

Difference Between Namespaces In .NET And C#?

Dec 12, 2009

In C#, if you do this, it will compile:

namespace Name
{
public class Test
{

[code]....

I get (depending on the way I try to use "Test") either "'Name' is not a member of '<Default>'." or "Type 'Name.Test' is not defined." in my error list. I've found two ways to make it work, but neither are reasonable to expect of a user. One is to remove the "Root Namespace" from the project properties. The other is to include that namespace between "Global" and "Name".

I have made a custom tool that uses CodeDom to generate code for both C# and VB.NET. This is the reason why neither of the two fixes above are feasible: I can't expect my users to have an empty root namespace, and I'd hate to have to do VB-specific tricks in my code generation (kind of defeats the purpose of using a language-neutral tool, doesn't it?) such as picking out the "Root Namespace" (not that I'd know how off the top of my head) and including it in my code generation.

I don't want to leave out the global modifier either, because it protects the tool from users picking bad names for the generated output. Does anybody have a suggestion for how I should deal with this?

View 1 Replies

One Class With Two Different Namespaces?

Jul 13, 2010

Is something like this possible?

Namespace Transaction, Document
Class Signer
Public Sub New()

[Code].....

I basically want to be able to instantiate the Signer class from either Namespace. The reason is that I mistakenly set it up in the Transaction class and need to migrate it over to the Document class without breaking existing legacy code. I'd prefer to not have the same Signer class duplicated in both Namespaces if possible.

View 3 Replies

Use Namespaces For The First Time?

Oct 19, 2010

I am building an ASP.Net application and want to use Namespaces for the first time. Within an App_Code folder, I have created three classes called RewriteContext, RewriteModule, and RewriteHandler.

[Code]...

View 10 Replies

XML Literals And Namespaces

Aug 30, 2010

I am using XML Literals and Linq to XML to read/write data to an external system.[code]The client now wants to put the url in a parameter table so the table can change to point to a test server or a real server. I assume that I cannot put a variable in my Imports statement.So how to I access the correct URL from a variable?url...

View 13 Replies







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