Ok so im trying to make it so that when a user posts the sitemap is automatically updated. Having a couple issues, i can get it to work, but only by breaking the sitemap "protocol".

So when a user posts i want to add the new url of that post to the sitemap, done easy. However when i do this i add the attribute "id" to the <url> tag so i can use xpath to easily update this if the post is modified.

So it looks like <url id="11">

Secondly when i user posts i want to update the <lastmod> tag of my main page, because that will also be updated (new post will be added to front page). This is fine however to achieve this i added the attribute id="index" to the url tag for my index page.

So it looks like <url id="index">

Also xpath wasnt working because i was using /urlset/url.... blah blah and the <urlset> tag was actually this:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

So i changed it to just <urlset>

Ok so i hope you're following

Now google says the following errors have occurs:

4 Invalid XML attribute
The XML attribute of this tag was not recognized. Please fix it and resubmit.
Tag:url
Attribute:id
Found:

2 Incorrect namespace
Your Sitemap or Sitemap index file doesn't properly declare the namespace. Tag:urlset

So i guess my question is:

How can i use xpath to grab the node object of a specific node without using the attribute, i.e how can i get it to find the url node where loc = "index" etc.

And also what do i put instead of /urlset/ ? Since that will not work.

Hope that makes sense lol its frustrating the hell outa me haha how important is a dynamic sitemap to a dynamic site?

Thanks in advance, Nick