How to convert a xml file to sql query -


i need on converting xml file sql query file. possible convert it?

<mob_proto isoldstructure="false">     <mob vnum="101" name="??" localizedname="cão selvagem" type="0" rank="0" battle_type="0" level="1" event_type="0" mob_color="0" /> </mob_proto> 

just give sense of how xslt might used this, consider following stylesheet:

<?xml version="1.0" encoding="utf-8" ?> <xsl:transform xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output method="text" doctype-public="xslt-compat" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />      <xsl:template match="//mob">         select *          <xsl:value-of select="local-name()" />          vnum = <xsl:value-of select="@vnum" />             , name = '<xsl:value-of select="@name" />'     </xsl:template>  </xsl:transform> 

this convert mob element select query, using 'mob' table name, , filtering on vnum , name column names. can play here: http://xsltransform.net/nc4nzqa

the advantages of approach:

  • xslt defined standards based langauge broad platform support.
  • xslt take care of lot of xml specific issues neatly
  • you potentially keep query transformation logic in 1 place

disadvantages:

  • your queries limited particular syntax/platform
  • xslt can challenging learn , may difficult team maintain

another option pass xml database engine. if, example, you're using sql server, write stored procedure takes xml parameter , uses openxml (https://msdn.microsoft.com/en-us/library/ms175160.aspx) extract/parse xml sent in. postgres has xml support: http://www.postgresql.org/docs/9.1/static/functions-xml.html, mysql: http://dev.mysql.com/doc/refman/5.5/en/load-xml.html, , oracle i'm sure well.

advantages approach:

  • may not steep learning curve proficient sql developer doesn't know xslt
  • may able load data directly database (either keeping in xml format or shredding tables) more efficiently

disadvantages:

  • support vary 1 db platform another
  • may put additional processing strain on db server more efficiently handled xslt processor on machine (especially if you're dealing complex document structure).

of course, use number of other custom utilities this, xslt or sql xml support best bets.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -