How to select XML attribute - Converting MSSQL to MySQL -


i need convert mssql query below mysql. query selects value of "id" attribute out of "page" element in xpath. expect mysql query return 3 rows values 1,2,3 respectively. know how in mysql? please let me know.

declare @inputxml xml set @inputxml = '<pages><page id="1"/><page id="2"/><page id="3"/></pages>'   select       node.value('@id', 'bigint') id      @inputxml.nodes('/pages/page') tempxml (node)) 

edit: forget said earlier.

courtesy of dave, want @ this:

http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html


(previous answer left in place reference):

mysql doesn't xml. short answer is: "you can't".

the long answer is, depending on context runs in, have few options.

  1. normalize data proper sql schema, instead of relying on xml inside sql.
  2. pull xml database plain strings, , xml processing in logic (php, c#, vb, whatever you're using). unfortunately, means can't filter data xpath expressions on database, you'll have pull in all candidate rows , discard ones don't want.
  3. ditch database altogether (at least part) , store xml files. if storing , retrieving xml files application does, , you're not adding meta-information, database has little no benefit.

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -