John Davidson

php - <markers></markers> at the top of the XLM file, instead of </markers> at bottom

0 comments
Message:


Good morning! My "reputation" is only "1," but I am hoping someone will help me with this Excessively Annoying Error (ENE). But damned if I can figure out how to make the code properly formatted here. I presume the problem is obvious to every human being but I. Thank you.


Firstly, the XLM result:


<?xml version="1.0" encoding="utf-8"?>
<markers></markers>
<marker site_name="Mineral Point Mine" mrds_id="D010915"</marker>

Then the code (if I can manage irt):


<?php
require("db.php");

$query = $_GET['query'];

function parseToXML($htmlStr) {
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;
$snode = $doc->createElement('markers', '');
$doc->appendChild($snode);

$link = mysqli_connect("localhost", $username, $password, $database);

if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}

$query = "{HIDDEN}";

$result = $link->query($query) or die($link->error);

while ($row = $result->fetch_assoc()) {

$node = $doc->createElement("marker","");
$newnode = $doc->appendChild($node);
$newnode->setAttribute("site_name", parseToXML($row['site_name']));
$newnode->setAttribute("mrds_id", parseToXML($row['mrds_id']));
}
$result->close();
echo $doc->saveXML();
?>


My Answer:
PHP is a server-side scripting language that is commonly used for web development. It can be embedded into HTML code and is often used to create dynamic web pages. PHP stands for Hypertext Preprocessor.

Rate this post

3 of 5 based on 7555 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us