Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Escaped XML

0 views
Skip to first unread message

Snozz

unread,
Sep 24, 2007, 8:06:43 PM9/24/07
to
I am trying to nest a string in an XML document, but the string itself
contains XML tags. I'm not sure how to get the DOM to treat the
string as just data instead of parsing the tags. The reason I want to
do this is because I will be calculating an MD5 across all the child
elements of the Message element, and there doesn't seem to be an easy
way to get all child elements as a string. I've seen code that loops
through all the children and reconstructs them as a string using the
name and attributes, but I'm afraid this makes too many assumptions
about spacing, as one space off would throw off the MD5.

My plan was to get the string of childelements, verify the MD5 of that
string, and then wrap them in a tag and do another domxml_open_mem on
that to parse, but I haven't gotten that far.

The get_content on the message element gives the child element values,
but not their tags(I did a view source to verify that the tags weren't
being hidden by the browser):
'(Client's)
FL075642
AdvData.mdb
StampHere'

I'm using PHP 4. Any suggestions?


<?php

$xmlMem= "<Payload>
<ProtocolVersion>
1.1
</ProtocolVersion>
<Message id=\"1\">
'<DHParam>(Client's)</DHParam>
<IdNumber>FL075642</IdNumber>
<Filename>Data.txt</Filename>
<TimeStamp>StampHere</TimeStamp>'
</Message>
<HMac id=\"1\">
ActualHMacHere
</HMac >
<HMacMessageAssociation>
<MessageReference ref=\"1\"/>
<HMacReference ref=\"1\"/>
</HMacMessageAssociation>
</Payload>";

$xmldoc = @domxml_open_mem($xmlMem,DOMXML_LOAD_PARSING,$error);

//print errors
echo "<pre>"; # Just for nice layout
foreach ($error as $errorline) { # Loop through all errors
echo $errorline['errormessage'];
echo " Node : " . $errorline['nodename'] . "\n";
echo " Line : " . $errorline['line'] . "\n";
echo " Column : " . $errorline['col'] . "\n\n";
}

$root = $xmldoc->document_element();

echo 'root->name = "'.$root->name."\"\n";

function parse_node($node,$callDepth)
{
$callDepthLoc = $callDepth +1;
if($callDepth > 5)
{
return;
}

if ($node->has_child_nodes())
{
foreach($node->child_nodes() as $n)
{

echo 'node_name = "'.$n->node_name()."\"\n";
echo 'node_value = "'.$n->node_value()."\"\n";
echo 'get_content = "'.$n->get_content()."\"\n";
// echo ' = '.$n->();


if($n->has_attributes())
{
foreach($n->attributes() as $a)
{
echo ' attribute name = "'.$a->name()."\"\n";
echo ' attribute value = "'.$a->value()."\"\n";
}
}

if ($n->node_type() == XML_ELEMENT_NODE)
{
parse_node($n,$callDepthLoc);
}
echo '</blockquote>';

}
}
}

parse_node($root,0);


echo "</pre>";

?>

0 new messages