", $ixml))); $xmlDoc = new DOMDocument(); $xmlDoc->load($firstone . ".xml"); $xml = $xmlDoc->documentElement; $tlist=explode(",", substr($typeslist,1)); //$nextbit=">"; $attribbit=""; $nonattribbit=""; $once=false; $jj=1; $kk=0; $ioff=1; foreach ($xml->childNodes AS $concept) { $bits=explode(" ", $concept->nodeValue); $attribbit=""; $ioff=1; $nonattribbit=""; for ($ii=$kk; $ii', ' ' . $firstset . ' ' . $nextbit . $attribbit . $nonattribbit . ' ', $outhtml); } } } $outhtml=str_replace("DIV", "div", $outhtml); return $outhtml; } // Expat method function do_expat($ixml) { global $ohtml, $parser, $rest, $atstart, $fp, $typeslist, $attribslist, $lastkey, $data; //echo $ixml; //return ""; $ohtml=analyze($ixml, true); $tlist=explode(",", substr($typeslist,1)); $lastkey=$tlist[0]; $atstart=true; $rest=""; //Initialize the XML parser $parser=xml_parser_create(); // Specify element handler xml_set_element_handler($parser,"start","stop"); // Specify data handler xml_set_character_data_handler($parser,"char"); // Open XML file file_put_contents($tlist[0] . ".xml", str_replace(" <", "<", str_replace("\n ", "\n", str_replace("> ", ">\n ", $ixml)))); $fp=fopen($tlist[0] . ".xml","r"); // Read data while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d %s", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser),strtoupper(substr($typeslist[0],0,1)) . strtolower(substr($typeslist[0],1)))); } // Free the XML parser xml_parser_free($parser); return str_replace("DIV", "div", $ohtml); //"

expat

"; } // Function to use at the start of an element function start($parser,$element_name,$element_attrs) { global $ohtml, $upto, $data, $typeslist, $attribslist, $ec, $en; $ec=$element_attrs; $en=$element_name; $tlist=explode(",", substr($typeslist,1)); $j=0; for ($i=0; $i"; if (1 == 2) $ohtml.="-- " . strtoupper(substr($tlist[0],0,1)) . strtolower(substr($tlist[0],1)) . " --" . $atts . "
"; break; case strtoupper($tlist[$j]): //"NOTE": if (1 == 9) { if (1 == 2) $ohtml.=strtoupper(substr($tlist[$j],0,1)) . strtolower(substr($tlist[$j],1)) . ":: " . $atts; $xone=strpos(strtolower($data), "<" . strtolower($tlist[$j]) . " "); $one=strpos(strtolower($data), "<" . strtolower($tlist[$j]) . ">"); $two=strpos(strtolower($data), ""); if ($one !== false && $two !== false) { $one++; $two--; if (strpos(substr($data, $one, ($two - $one)), "<") !== false) { $ohtml=str_replace('', ' ' . $firstset . '
' . $thisnonattrib . '
', $ohtml); $thisattrib=""; $thisnonattrib=""; $lastkey=$tlist[$j]; } } else if ($xone !== false && $two !== false) { $xone++; $two--; if (strpos(substr($data, $xone, ($two - $xone)), "<") !== false) { $ohtml=str_replace('', ' ' . $firstset . '
' . $thisnonattrib . '
', $ohtml); $thisattrib=""; $thisnonattrib=""; $lastkey=$tlist[$j]; } } } break; } } // Function to use at the end of an element function stop($parser,$element_name) { global $ohtml, $data, $typeslist, $attribslist, $firstone, $firstset, $thisattrib, $thisnonattrib, $lastkey; $tlist=explode(",", substr($typeslist,1)); $j=0; for ($i=0; $i"; switch($element_name) { case strtoupper($tlist[0]): //"NOTE": if (($thisattrib != "" || $thisnonattrib != "")) $ohtml=str_replace('', ' ' . $firstset . '
' . $thisnonattrib . '
', $ohtml); $thisattrib=""; $thisnonattrib=""; //$lastkey=$tlist[0]; break; case strtoupper($tlist[$j]): //"NOTE": if (1 == 1) { $xone=strpos(strtolower($data), "<" . strtolower($tlist[$j]) . " "); $one=strpos(strtolower($data), "<" . strtolower($tlist[$j]) . ">"); $two=strpos(strtolower($data), ""); if ($one !== false && $two !== false) { $one++; $two--; if (strpos(substr($data, $one, ($two - $one)), "<") !== false && ($thisattrib != "" || $thisnonattrib != "")) { $ohtml=str_replace('', ' ' . $firstset . '
' . $thisnonattrib . '
', $ohtml); $thisattrib=""; $thisnonattrib=""; //$lastkey=$tlist[$j]; } } else if ($xone !== false && $two !== false) { $xone++; $two--; if (strpos(substr($data, $xone, ($two - $xone)), "<") !== false && ($thisattrib != "" || $thisnonattrib != "")) { $ohtml=str_replace('', ' ' . $firstset . '
' . $thisnonattrib . '
', $ohtml); $thisattrib=""; $thisnonattrib=""; //$lastkey=$tlist[$j]; } } } if (1 == 2) $ohtml.="
"; break; } } // Function to use when finding character data function char($parser,$data) { global $ohtml, $ec, $typeslist, $attribslist, $en, $thisattrib, $thisnonattrib, $lastkey, $firstset, $firstone; $tlist=explode(",", substr($typeslist,1)); //echo $data; if (1 == 2) $ohtml.=$data; if (strtolower($en) != strtolower($lastkey) && strpos(strtolower($firstset), "/" . strtolower($en)) === false && strpos(strtolower($firstone), strtolower($en)) === false) { $thisnonattrib.=" data-" . strtolower($en) . '="' . $data . '" '; $thisattrib.=" data-" . strtolower($en) . '="' . $data . '"'; } $lastkey=$en; if (is_array($ec)) { while(list($key,$val) = each($ec)) { if (strtolower($key) != "id" && strtolower($key) != "title" && strtolower($key) != "alt" && strtolower($key) != "style") { if (strtolower($key) != strtolower($lastkey)) { //$ohtml.=" data-" . strtolower($key) . '="' . $val . '"'; $thisattrib.=" data-" . strtolower($key) . '="' . $val . '"'; $thisnonattrib.=" data-" . strtolower($key) . '="' . $val . '"'; $lastkey=$key; } } else { //$ohtml.=" " . $key . '="' . $val . '"'; $thisattrib.=" " . $key . '="' . $val . '"'; } } } } // Used by SimpleXML and Expat and Document DOM methods function analyze($ixml, $just) { global $typeslist, $attribslist, $firstone, $firstset, $thismode, $xeattribbit, $xenonattribbit, $nextbit; $outhtml=""; $nextbit='
'; $eattribbit='$attribbit = ' . "'';"; $xeattribbit='$attribbit .= ' . "'';"; $attribbit=""; $enonattribbit='$nonattribbit = ' . "'';"; $xenonattribbit='$nonattribbit .= ' . "'';"; $nonattribbit=""; $trythese=false; $firstone=""; $firstset=""; $typeslist=","; $attribslist=","; $xbits=explode(" 1) { $prexbits=explode("?>", $xbits[1]); $ixml=str_replace("", "", $ixml); } $parts=explode("<", $ixml); for ($i=1; $i", " ", $parts[$i])); if (strpos($typeslist, "," . $subpart[0] . ",") === false) { if ($trythese) { if (strpos($ixml, "<" . $subpart[0] . ">") !== false && strpos($ixml, "") !== false) { $one=strpos($ixml, "<" . $subpart[0] . ">"); $one++; $two=strpos($ixml, ""); $two--; if (strpos(substr($ixml, $one, ($two - $one)), "<") !== false) { $firstset .= "/" . $subpart[0]; $nextbit=str_replace('">', $subpart[0] . '">', $nextbit); } else { $trythese=false; } } else if (strpos($ixml, "<" . $subpart[0] . " ") !== false && strpos($ixml, "") !== false) { $one=strpos($ixml, "<" . $subpart[0] . " "); $one++; $two=strpos($ixml, ""); $two--; if (strpos(substr($ixml, $one, ($two - $one)), "<") !== false) { $firstset .= "/" . $subpart[0]; $nextbit=str_replace('">', $subpart[0] . '">', $nextbit); } else { $trythese=false; } } } if ($firstone == "") { $firstone=$subpart[0]; $firstset=$firstone; $trythese=true; } else if ($trythese == false && strpos($subpart[0], "/") === false) { //if (strpos($enonattribbit, $subpart[0]) === false) $enonattribbit=str_replace(" = ", " = ' data-" . $subpart[0] . '="' . "'" . ' . $concept->' . $subpart[0] . " . " . "'" . '"' . "'" . ' . ', $enonattribbit); if (strpos($enonattribbit, $subpart[0]) === false) $enonattribbit=str_replace(";", " . ' data-" . $subpart[0] . '="' . "'" . ' . $concept->' . $subpart[0] . " . " . "'" . '"' . "'" . ' . ' . "'';", $enonattribbit); if (strpos($eattribbit, $subpart[0]) === false && strpos($attribbit, $subpart[0]) === false) { if ($attribbit == "") { $eattribbit='$attribbit = ' . "'>';"; $xeattribbit='$attribbit .= ' . "'>';"; $attribbit=">"; } $eattribbit=str_replace("= ", "= ' data-" . $subpart[0] . '="' . "'" . ' . $concept->' . $subpart[0] . " . " . "'" . '"' . "'" . ' . ', $eattribbit); } //if (strpos($xenonattribbit, $subpart[0]) === false) $xenonattribbit=str_replace(";", " . ' data-" . $subpart[0] . '="' . "'" . ' . $concept->' . $subpart[0] . " . " . "'" . '"' . "'" . ' . ' . "'';", $xenonattribbit); } $typeslist .= $subpart[0] . ","; } $ok=true; for ($j=0; $jgetAttribute(' . "'" . $pep[0] . "')" . " . " . "'" . '"' . "'" . ' . ' . "'';", $xenonattribbit); } else { if ($attribbit == "") { $eattribbit='$attribbit = ' . "'>';"; $xeattribbit='$attribbit .= ' . "'>';"; $attribbit=">"; } $eattribbit=str_replace("= ", "= '" . $pep[0] . '="' . "'" . ' . $concept[' . "'" . $pep[0] . "']" . " . " . "'" . '"' . "'" . ' . ', $eattribbit); $xeattribbit=str_replace("= ", "= '" . $pep[0] . '="' . "'" . ' . $concept->getAttribute(' . "'" . $pep[0] . "')" . " . " . "'" . '"' . "'" . ' . ', $xeattribbit); if (strpos($nextbit, '"' . $subpart[0] . '"') !== false) $nextbit=str_replace('">', '" ', $nextbit); } } } } if (strpos($presubparts[$j], ">") !== false) { $ok=false; } } } } if (!$just) { // SimpleXML method file_put_contents($firstone . ".xml", str_replace("<", "<", str_replace(">", ">", $ixml))); $xml=simplexml_load_file($firstone . ".xml") or die("Error: Cannot create object"); $outhtml='
'; foreach($xml->children() as $concept) { eval($eattribbit); eval($enonattribbit); $outhtml=str_replace('
', ' ' . $firstset . ' ' . $nextbit . $attribbit . $nonattribbit . ' ', $outhtml); } $outhtml=str_replace("DIV", "div", $outhtml); } else { $outhtml='
'; } return $outhtml; } function server_remote_addr() { $rma = $_SERVER['REMOTE_ADDR']; $ua = strtolower($_SERVER['HTTP_USER_AGENT']); // you can add different browsers with the same way .. if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua)) $rma = '000000'.$rma; elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua)) $rma = '00000'.$rma; elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua)) $rma = '0000'.$rma; elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua)) $rma = '000'.$rma; elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua)) $rma = '00'.$rma; elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua)) $rma = '0'.$rma; return str_replace(":", "_", $rma); } if (isset($_GET['inxml']) && file_exists("xml_to_html.html")) { $inxml=urldecode($_GET['inxml']); if (strpos(strtolower($thismode), "simplexml") !== false) { if (strpos($_SERVER['HTTP_REFERER'], "xml_to_html.html") !== false && strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") !== false) { header("Location: ./xml_to_html.html?inxml=" . $_GET['inxml']); exit; } } else if (strpos(strtolower($thismode), "expat") !== false) { $outhtml=do_expat($inxml); } else if (strpos(strtolower($thismode), "dom") !== false) { $outhtml=do_dom($inxml); } } else if (isset($_POST['inxml']) && file_exists("xml_to_html.html")) { $inxml=urldecode($_POST['inxml']); if (strpos(strtolower($thismode), "simplexml") !== false) { if (strpos($_SERVER['HTTP_REFERER'], "xml_to_html.html") !== false && strpos($_SERVER['HTTP_REFERER'], "rjmprogramming.com.au") !== false) { $pinxml=$_POST['inxml']; $xbits=explode(" 1) { $prexbits=explode("?>", $xbits[1]); $pinxml=str_replace("", "", $pinxml); } $okhtml=@file_get_contents("xml_to_html.html"); $bits=explode('var preinxml="', $okhtml); if (sizeof($bits) > 1) { $subbits=explode('"', $bits[1]); $newhtml=str_replace($subbits[0], str_replace("\n", " ", str_replace("\r", " ", str_replace('"', '\"', str_replace("<","<",str_replace(">",">",urldecode($pinxml)))))), $okhtml); file_put_contents("xmltohtml" . server_remote_addr() . ".html", $newhtml); header("Location: xmltohtml" . server_remote_addr() . ".html"); exit; } else { header("Location: ./xml_to_html.html?inxml=" . $_POST['inxml']); exit; } } else if (strpos(strtolower($thismode), "expat") !== false) { $outhtml=do_expat($inxml); } else if (strpos(strtolower($thismode), "dom") !== false) { $outhtml=do_dom($inxml); } } } else if (isset($_POST['inxml'])) { $inxml=urldecode($_POST['inxml']); if (1 == 2) { $pinxml=$_POST['inxml']; $xbits=explode(" 1) { $prexbits=explode("?>", $xbits[1]); $pinxml=str_replace("", "", $pinxml); } } } if ($inxml != "") { if (strpos(strtolower($thismode), "simplexml") !== false) { $outhtml=analyze($inxml,false); } else if (strpos(strtolower($thismode), "expat") !== false) { $outhtml=do_expat($inxml); } else if (strpos(strtolower($thismode), "dom") !== false) { $outhtml=do_dom($inxml); } } else { $inxml="<messages> <note id='501'> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> <note id='502'> <to>Jani</to> <from>Tove</from> <heading>Re: Reminder</heading> <body>I will not</body> </note></messages>"; file_put_contents("messages.xml", str_replace("<", "<", str_replace(">", ">", $inxml))); if (strpos(strtolower($thismode), "simplexml") !== false) { $xml=simplexml_load_file("messages.xml") or die("Error: Cannot create object"); $outhtml='
'; foreach($xml->children() as $note) { $outhtml=str_replace('', ' messages/note
data-to="' . $note->to . '" data-from="' . $note->from . '" data-heading="' . $note->heading . '" data-body="' . $note->body . '"
', $outhtml); } $outhtml=str_replace("DIV", "div", $outhtml); } else if (strpos(strtolower($thismode), "expat") !== false) { $outhtml=do_expat($inxml); } else if (strpos(strtolower($thismode), "dom") !== false) { $outhtml=do_dom($inxml); } } $thehtml=" XML to HTML - PHP via SimpleXML or Expat or Document DOM - RJM Programming - September, 2015 - via http://www.w3schools.com/xml/xml_attributes.asp var preqs=location.search.split('addressbook=')[1] ? location.search.split('addressbook=')[1].split('&')[0] : 'y'; var qs='?addressbook=' + (location.search.split('noaddressbook=')[1] ? location.search.split('noaddressbook=')[1].split('&')[0].toLowerCase().replace('y','n') : preqs); function changemode(so, si, sv) { document.getElementById('imode').value=sv; } /" . "/ A business logic idea ... messages/note XML with defined id= are user interactively emailable function checkforemail() { " . $fbit . " var ee, eo, preiu, iu, predivs,divs=[],cdivs; var ecnt=0; var oto='', ofrom='', osubject='', obody=''; predivs=document.body.innerHTML.toLowerCase().split(' id='); for (preiu=1; preiuFrom ' + ofrom + \"\"; ecnt++; } } } if (ecnt > 0) { for (var iuc=eval(-1 + ecnt); iuc>=0; iuc--) { eo=document.getElementById('email' + iuc); eo.click(); } } " . $ebit . " } /" . "/ A business logic idea ... client pre-emptive iframe ... address book function getaddressbook(iois) { var qbits, ie, je, edelim='\"', bdone=false; var idx=['<to>','','','','data-to=\"','<from>','','','','data-from=\"','<cc>','','','','data-cc=\"','<bcc>','','','','data-bcc=\"']; if (iois != null) { var aconto = (iois.contentWindow || iois.contentDocument); if (aconto != null) { if (aconto.document) { aconto = aconto.document; } if (aconto.body != null) { addresscont=aconto.body.innerHTML.replace(/\\n/g, ','); var emailinfo=addresscont.split(','); for (ie=1; ie= 3) { tas[2].innerHTML=tas[0].innerHTML; fs[0].submit(); } }

XML to HTML - PHP via - RJM Programming - September, 2015

XML ----> Display ----> HTML5
----> " . $outhtml . " ---->
" . "





"; echo $thehtml; ?>