.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


ADVERTISEMENT

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

Opened An Xml Stream And Am Reading It Using Xmltextreader?

Jul 6, 2009

i am using visual studio 2008 using vb.net. I have opened an xml stream and am reading it using xmltextreader. So far so good. I am using the following code to parse the stream and to get an understanding of what it contains and how to use the info.

[Code]...

View 1 Replies

Cannot Convert System.Xml.XmlNode To System.Xml.Linq.XElement

Nov 24, 2010

I´m gettin the error Calling the fuction GetListItems but is kind weird because it works in Visual Studio 2008 Express but no in Visual Basic 2010 Express:

Dim ndQuery As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")
Dim ndViewFields As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "")
Dim ndQueryOptions As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element,

[Code].....

View 1 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

Error 1 Operator '&' Is Not Defined For Types 'String' And 'System.Xml.Linq.XElement'

May 17, 2012

i am downloading data from xml using linq library those data i want to add them on a textblock item

TextBlock1.Text = TextBlock1.Text & result

but it has an error :

Error 1 Operator '&' is not defined for types 'String' and 'System.Xml.Linq.XElement'.

When i am changing this line to :

TextBlock1.Text = TextBlock1.Text & result.Tostring

it works but it adds this data :

"<"data> data <"/data>

instead of :

hello

View 1 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 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

Cannot Convert To 'System.IO.Stream

Jul 31, 2011

I am trying to convert the image from 'System.Drawing.Bitmap' to 'System.IO.Stream', but i am getting an error.

the error is: Value of type 'System.Drawing.Bitmap' cannot be converted to 'System.IO.Stream'.[code]...

View 1 Replies

Asp.net - Convert The Encoding Type Of A Stream In .NET?

Dec 27, 2010

I ve the following stream but I don't know its encoding type because the stream reader detects encoding from byte order marks

Dim reader As StreamReader = New StreamReader(respStream, True)

so how can I detect the encoding type AND convert it to another type? (for ex. from ASCII to UTF8)

PS: What is the difference with the following line?

Dim reader As StreamReader = New StreamReader(respStream,
Encoding.ASCII, True)

View 1 Replies

C# - Convert An Image In To A Stream Of Characters?

Sep 17, 2010

I have found that an image can be stored as some string. To give an example I have included a ms word part that has an image.I saved a word file with image and saved it as xml format .when i opened the xml file in a notepad i got following section. It must be the image being stored as some stream of text. Is there a similar way to do it in .net.

[Code]....

View 4 Replies

Convert A Byte Stream To A Text String?

Mar 31, 2011

I'm working on a licensing system for my application. I'd like to put all licensing information (licensee name, expiration date, and enabled features) into an object, encrypt that object with a private key, then represent the encrypted data as a single text string which I can send via email to my customers.

I've managed to get the encrypted data into a byte stream, but I don't know how to convert that byte stream into a text value -- something that contains no control characters or whitespace. Can anyone offer advice on how to do that? I've been researching the Encoding class, but I can't find a text-only encoding.

View 3 Replies

Convert Binary Stream Into Double Array?

Aug 5, 2009

How to convert a binary stream (which is a string of numbers) into Double Array ? (VB.NET 2008)

View 3 Replies

Stream (and Convert?) Multi-page TIFF?

Aug 10, 2009

I have built a simple image viewer in .NET and have the requirement to display multi-frame TIFF images in the browser. Presently, I have a (ashx) handler setup to stream back JPEGs that are co-mingled in the same database as the multi-frame TIFF's and it's worth mentioning that this handler will also return the first frame of the TIFF file in its current state. In the VB.NET code below (part of the handler) I am able to identify if a TIFF file has multiple frames and I started attempting to stitch the frames together but have not had any success yet. Has anyone returned multi-frame TIFF's using a similar approach? Note: I used the How to open a multi-frame TIFF image as a reference when developing the code below.

context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.Cache.SetNoStore()
context.Response.Cache.SetExpires(DateTime.MinValue)

[code].....

View 2 Replies

C# - Convert Code LINQ To SQL In C # LINQ To SQL In .net?

Jun 27, 2012

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

[Code]...

View 2 Replies

Convert An Object System.Data.Linq.DataQuery To System.Linq.IQueryable?

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

.net - Xml Parsing Using Xmltextreader?

Dec 5, 2010

I am parsing some xml entries using the xmltextreader and looking for the elements I need by using different textreaders for each in a different loop as follows:

Dim treader As XmlTextReader = New XmlTextReader(New StringReader(item.ToString))
While treader.Read
If treader.Name = "summary" Then
content = treader.ReadElementContentAsString

[code].....

and I do the same for each element I am looking for. Now the problem arises when I get the results for each. I use an arraylist for each element and at times I will have an unequal amount like 100 for summary, 100 for title , 99 for id etc...is there a more efficient way of doing this by checking the entry if all the nodes are there and then just skipping it if it's not.

<entry>
<summary>
<id>

[code].....

View 1 Replies

Stream Read Return Length 0 While Stream Is Open And Has Valid Data In It?

May 25, 2012

in an winForm app in VS2010 win 7 compiling to x86, I try to do what Alvas.Audio seems to work. See (c# ex: [URL] for reference.

Dim data() As Byte = wr.ReadData(second * i, second)

The result give me data.length()=0. I do not have any exception, I can read format from it and whatever reader I use I got this problem.EDIT : After some tests, it seems like the uncompressed file I create in the first step (in PCM format, with .wav extension) can not be recognized by the Alvas.audio library for the second step. I must miss something around Audio file markups or something alike.

Here is the code that might be the source (basically this is step 1):

Dim functOut As String = String.Empty
Dim wr As Alvas.Audio.IAudioReader = Nothing
Dim fs As IO.FileStream = Nothing

[code]....

How can I write the resulted stream to be sure I can read it again later?

View 1 Replies

Change Byte() To Structs For Readability And Convert Struct To Byte Stream For Socket Send()

Dec 8, 2009

I just converted the following code from c# to vb.net. It is functional and works correctly with my company's firmware/devices. My next challenge. Previous serialport code used much more readable structs which where then converted (after building a packet) into byte() automatically as part of the serialport encoding. (this is my understanding)How could I

1. morph byte arrays 'ToSocket' and 'ToMTP' below into structs and

2. convert into byte array for Socket.BeginSend(byte(),.....) to stream out to remote devices?


Imports System.ComponentModel
Imports System.Text
Imports System.Net.Sockets

[Code]....

View 3 Replies

.net - Use XmlTextReader To Extract Values?

Jul 18, 2011

I'm trying to parse this XML for the values of puppies and kittens.

<Pets>
<Puppies>4</Puppies>
<Kittens>2</Kittens>
</Pets>

Here's my code

[Code]...

On the first read, the element name is "Pets" and the Case Else gets hit. On the next read, the element name is "Puppies" and puppyCount is correctly set to 4.

But then it seems to skip over "Kittens" and go directly to the inner XML. What should I be doing?

EDIT: XmlReader is faster than other .NET parsers, but my files are small enough that it's probably not a benefit. Joe Ferner's tests. EDIT 2: There's a reader positioning problem in the original code.

View 1 Replies

Convert C# Linq To VB?

Jul 26, 2011

How can I convert below code to vb.net.

[code]...

View 2 Replies

Linq To Sql - Convert C# To .NET?

Oct 20, 2009

I'm having trouble converting a C# Linq statement to VB.NET. I need the following statement converted. I am getting hung up on the i.Sum(v=>v) part.

from p in Products
from u in Users
let i = (from op in OrderProducts
where op.Order.User == u && op.Product == p

[code]....

how to get that converted to VB.NET and working?

View 1 Replies

How To Put XMLTextReader Cursor Back To Start

May 9, 2012

I've got a function api_request which takes API method as an argument, and returns XMLTextReader.
Shared Function api_request(method As String) As XmlTextReader
request_text = method & ".xml"
url = "[URL]" & request_text & "&access_token=" & token
Return New XmlTextReader(url)
End Function

I call this function from different places to make request to site API and depending on the method results are parsed very differently. So in each method I have something like this:
Dim s As Xml.XmlReader = api_request("users.get")
While s.Read
If s.NodeType = XmlNodeType.Element Then
If s.Name = "user" Then
[Code] .....

As you may see, I have the code ElseIf s.Name = "error" Then error_handler(s, "user.get"). This is because when error happens, server always returns something like this:
<error>
<error_code>4</error_code>
<error_msg>Incorrect signature</error_msg>
</error>

This is parsed in error_handler Sub, and depending on the error following actions are chosen. This code works, but I have to check if I encounter error like that ElseIf s.Name = "error" every time, though all the methods call the api_request function. Is it possible to check for error in api_request function before returning the Reader? The problem is if I start reading xml there, and there isn't an error, I can't anyhow position the Reader to the start.

View 1 Replies

Xml - .Net XMLTextReader Keeps Skipping 1st Element In Children?

Jul 1, 2011

I'm hoping somebody can help me with this... I am reading an XML file created from the server and all is good except that when I try to process the file it's always skipping one of the first child elements. And when I run a test with no processing, just a straight reader and looping through the elements, the 1st element is there. But as soon as I add a check to see if the node is an Element, it skips an "Attachment" element.Here's my XML:

[Code]...

View 1 Replies

XMLTextReader IO Exception (File In Use By Another Process)

Dec 15, 2011

I'm trying to build a program updater based around downloading XML files from a server. The idea being that the servers XML file contains the current version number and installer location. the updater either gets dumped in the startup folder or gets installed as a service, etc. The program successfully reads and parses the current version xml file and it successfully downloads the xml file from the server.

However when I try to parse the newly downloaded file from the server I get the error:
'IOException was unhandled'
'The process cannot access the file 'C:Program Files (x86)TestServerVersion.xml' because it is being used by another process.'

The code is as follows with the error marked by a comment on line 52:
Imports System.IO
Imports System.Xml.XmlTextReader
Imports System.Net
Module Module1
[Code] .....

It's still work in progress but there's not much point in writing code to download and execute the installer if I can't work out the location of the new version. In case it's of use here is the XML:
<?xml version="1.0" encoding="UTF-8"?>
<VersionConfig>
<AvailableVersion>2.0.0.0</AvailableVersion>
<ApplicationUrl>http://192.168.2.226/EPI/2.0.0.0/</ApplicationUrl>
</VersionConfig>

View 1 Replies

.net - Convert DataTable To Linq?

Feb 10, 2010

I'm trying to convert DataTable to Linq using

DIm result = From r in dt.AsEnumerable()
Select new ( col1 = r.Field<integer>("id"), col2 = r.Field<string>("desc"))

But i get error near 'new (' saying type expected.

View 2 Replies

Convert C# To VB (LINQ - RemoveAll)?

Sep 13, 2009

I have this book from sanders (Pro MVC 1) and the code below is what I'm trying to convert from C# to VB.

public void RemoveLine(Product product)
{
lines.RemoveAll(l => l.Product.ProductID == product.ProductID);
}

However, I don't have the intellisense for the RemoveAll method. [:(]

Public Sub RemoveLine(ByVal product As ProductModel)
Lines.RemoveAll(Function(c) c.Product.ProductID = product.ProductId)
End Sub

View 7 Replies

Convert Linq.expression From C# To VB?

Mar 30, 2010

[QueryInterceptor("Somethings")]
public Expression<Func<Something, bool>> OnSomethings()
{
// Code here
}

I had a view guesses, looked on msdn, but there are no examples matching the way that that is used.

View 1 Replies







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