views:

339

answers:

1

My customer doesn't want a database but would prefer to update their data in an XML file. This is all well and good. However, they also want their items to be submitted to Google products. This complicates things a bit. I decided to attempt to just use the Google XML file for the database rather than create and maintain two separate files, but I've just hit a roadblock. My XML is like this:

<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns:g="http://base.google.com/ns/1.0" 
xmlns:c="http://base.google.com/cns/1.0" xmlns="http://www.w3.org/2005/Atom"&gt;
<title>Company Product and Price Catalog</title>
<link rel="self" href="http://www.example.com" />
<author>
 <name>Some Company</name>
</author>
<id>tag:example.com:/App_Data/</id>
 <entry>
             <id>1</id>
     <title>Product Title</title>
     <g:price>100.00</g:price>
     <link href="http://www.example.com/product" />
        <g:image_link>http://www.example.com/images/product.jpg&lt;/g:image_link&gt;
     <g:condition>new</g:condition>
     <g:brand>Brand Name</g:brand>
     <payment_accepted>cash,check,invoice,amex,discover,mastercard,
visa,googlecheckout</payment_accepted>
     <g:payment_notes>Google Checkout accepted</g:payment_notes>
 </entry>
....

And my code to extract this data is like this:

Dim allItems As New List(Of CartItem)
  Dim productXML As XDocument = XDocument.Load( _
Current.Server.MapPath("/App_Data/products.xml"))


 Dim productsDoc = System.Xml.Linq.XDocument.Parse(productXML.ToString())
 Dim products = From entry In productsDoc...<entry> Select entry

 For Each entry In products
  Dim product As New CartItem
  Dim nameAndOptions() As String = Split(entry.<title>.Value, " - ")
  product.ProductName = nameAndOptions(0)
  If nameAndOptions.Length = 2 Then
   product.[Option] = nameAndOptions(1)
  End If
  product.Price = entry.<g:price>.Value 'problem here!'
  product._productid = entry.<id>.Value
  product._permalink = entry.<link>.Value
  allItems.Add(product)
 Next

 Return allItems

A blue squiggly line appears in VS08 under the "g" in "g:price" with the error, "xml namespace prefix 'g' is not defined". How do I fix this? Or is this just a bad idea and I should go back to maintaining two separate files?

Thank you!

+2  A: 

Try adding the following line to the top of your file:

Imports <xmlns:g="http://base.google.com/ns/1.0"&gt;

(I've never done VB 2008, so the syntax may be off)

EDIT: See here.

SLaks
I'm trying the following, but the debug is giving me a count of 0 instead of 8:Dim allItems As New List(Of CartItem) Dim productXML As XDocument = XDocument.Load(Current.Server.MapPath("/App_Data/g-attempt.xml")) Dim productsDoc = XDocument.Parse(productXML.ToString()) Dim products = From entry In productsDoc...<entry> Select entry Debug.Assert(False, products.Count)What am I doing wrong?
Jason
Can you put that into your question so that it gets formatted?
SLaks
FIGURED IT OUT! not only do i have to add the imports statement you mentioned, but i also have to add: Imports <xmlns="http://www.w3.org/2005/Atom">THANK YOU SO MUCH!
Jason