473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help - LINQ to XML Issues

Hi,

Using LINQ with xml files is a breeze, much easier than working with other methods IMO.
But I've run into a bit of a snag with it.

You see, I have an xml file that look like this:

<?xml version="1.0" encoding="utf-8"?>
<merchandiser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="merchandiser.xsd">

<!-- a list of product nodes exist here -->

</merchandiser>

All is great. In my VB program, I import an xml namespace to use when reading this xml
file, like this:

Imports <xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
So far so good. Now, in code I read the contents of the xml file like this:

Dim xdoc as XDocument = XDocument.Load("C:\merchandiser.xml")
dim brands = from p in xdoc.<xsi:productSelect p.<xsi:brand>.Value
That seems simple enough. However, testing reveals that the "brands" variable contains
absolutely nothing. No error is ever thrown when the code runs.

This is the first time I've worked with a file with two namespaces declared, and I don't
know how to work with both using LINQ.

Can anyone help me?
Roshawn
Jul 25 '08 #1
4 1805
*** Bump ***
Jul 25 '08 #2
*** Bump ***
Jul 26 '08 #3
Okay, here's a sample of the xml I'm working with, including the namespace and all:
<?xml version="1.0" encoding="utf-8"?>
<merchandiser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="merchandiser.xsd">
<header>
<merchantId>1805</merchantId>
<merchantName>Forzieri.com / Firenze Seta srl</merchantName>
<createdOn>2008-07-27/12:50:34</createdOn>
</header>
<product name="Jules - Metallic Eco-Leather Evening Clutch">
<category>
<primary>Handbags</primary>
<secondary></secondary>
</category>
<price currency="USD">
<sale begin_date="" end_date=""></sale>
<retail>287.00</retail>
</price>
<brand>Francesco Biasia</brand>
<keywords>Handbags~~Francesco Biasia</keywords>
</product>
<product name="Brown Nylon Satchel">
<category>
<primary>Handbags</primary>
<secondary></secondary>
</category>
<price currency="USD">
<sale begin_date="" end_date=""></sale>
<retail>602.00</retail>
</price>
<brand>Miu Miu</brand>
<keywords>Handbags~~Miu Miu</keywords>
</product>
<product name="Black Leather Tote">
<category>
<primary>Handbags</primary>
<secondary></secondary>
</category>
<price currency="USD">
<sale begin_date="" end_date=""></sale>
<retail>549.00</retail>
</price>
<brand>Prada</brand>
<keywords>Handbags~~Prada</keywords>
</product>
<!-- more product nodes follow -->
</merchandiser>
Please, can someone help me? :(
Jul 27 '08 #4
I found a simple solution to the problem by removing the attributes of the root node (use
the XElement's RemoveAllAttributes method). After doing this, everything worked!
Jul 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: =?Utf-8?B?V2lsc29uIEMuSy4gTmc=?= | last post by:
Hi Experts, I am doing a prototype of providing data access (read, write & search) through Web Service. We observed that the data storing in SQL Server 2005, the memory size is always within...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
7
by: Adrian | last post by:
Hi, I'm trying to add caching to our asp app, but am having problems with the SQLCacheDependancy not invalidating the cache when the table changes. Using vs2008, sqlserver 2005 developer edition....
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.