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">
<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</g:image_link>
<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!