Jump to content

problem in generating XML file


tanveer

Recommended Posts

Hi,

I am using php to generate an xml file of the following structure

<?xml version="1.0" encoding="UTF-8"?>

<!--  An excerpt of an egocentric social network  -->

<graphml xmlns="http://graphml.graphdrawing.org/xmlns">

<graph edgedefault="directed">



<!-- data schema -->

<key id="name" for="node" attr.name="name" attr.type="string"/>

<key id="gender" for="node" attr.name="gender" attr.type="string"/>



  

<!-- nodes -->  

<node id="1">

<data key="name">Jeff</data>

<data key="gender">M</data>

</node>

<node id="2">

<data key="name">Ed</data>

<data key="gender">M</data>

</node>

<node id="3">

<data key="name">Christiaan</data>

<data key="gender">M</data>

</node>

<node id="4">

<data key="name">Emily</data>

<data key="gender">F</data>

</node>

<node id="5">

<data key="name">Adam</data>

<data key="gender">M</data>

</node>

<!-- emily's friends -->

<edge source="1" target="2"></edge>

<!-- adam's friends -->

<edge source="2" target="3"></edge>

<!-- cynthia's friends -->

<edge source="3" target="4"></edge>

<!-- joylette's friends -->

<edge source="4" target="5"></edge>

<!-- amanda's friends -->

<edge source="5" target="1"></edge>

<edge source="5" target="2"></edge>
<edge source="5" target="3"></edge>

<edge source="5" target="4"></edge>



</graph>

</graphml>

 

and below is my code:

	public function createXML($resultID){


	header("Content-type: text/xml");
	$xml_output  = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	$xml_output .= "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\">\n";
        $xml_output .= "<graph edgedefault=\"directed\">\n";

	$xml_output .= "<key id=\"name\" for=\"node\" attr.name=\"sender\" attr.type=\"string\"/>\n";

	for($x = 1 ; $x < mysql_num_rows($resultID) ; $x++){
		$row = mysql_fetch_assoc($resultID);
		$xml_output .= "\t<node id=$x>\n";
		$xml_output .= "\t\t<data key=\"name\">" . $row['sender'] . "</data>\n";
		$xml_output .= "\t</node>\n";
	}

	$xml_output .= "</graph>\n";
	$xml_output .= "</graphml>";

	echo $xml_output;

}


}

$snxml = new SocialNetworkXML;
$holdResult = $snxml->setQuery("select sender from message1");
$snxml->createXML($holdResult);

 

But in browser its giving me this message:

XML Parsing Error: not well-formed
Location: http://localhost/........./SocialNetXML.class.php
Line Number 5, Column 11:	<node id=1>
-----------------^

 

What am I doing wrong here ? thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/237761-problem-in-generating-xml-file/
Share on other sites

The error points you right at the location of the problem (between the equals sign, and the 1).  In XML, attributes must be wrapped in quotes (single or double, it doesn't matter). So, your resulting XML needs to look like: <node id="1">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.