How to read XML data from SQL Server into PHP -


i trying convert number of sql server xml queries , xsl templates, legacy asp application php.
app assembles xml document several queries uses xsl template output html.

i have being reading blog post:

i using sqlsrv_query() followed sqlsrv_fetch() , sqlsrv_get_field() data. result set returned default xml stream.

i can't figure out how read stream domdocument object. guess can convert output string, parse string object, how read xml stream directly?

if fetching data hinting php-data-type shown in blog-post you've linked:

$xml = sqlsrv_get_field($stmt, 0, sqlsrv_phptype_string('utf-8')); 

then variable $xml contains utf-8 encoded string. strings in php binary , utf-8 default encoding of xml document. same in php: domdocument in php expects input strings utf-8 encoded (as outlined in introductiondocs).

all need load xml stringdocs:

$doc   =  new domdocument(); $result = $doc->loadxml($xml); 

you can verify if works checking return value , outputting xml string document:

var_dump($result);          # should (boolean) true $doc->save('php://output'); # should xml verbatim 

this should it, let me know if use different way fetch database. because might work differently, e.g. if getting a php streamdocs might want use stream_get_contents()docs convert stream string first. can not load streams domdocument in php, why need convert first string.

see well:


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -