 |
Use the CAML encoder and decoder to encode or decode CAML while working with SharePoint Data Source Control queries. This script utilizes both HTML rendering to decode and a PHP function to encode. And, of course, I have included the simple script below for those that are curious.
show me!
|
<html>
<head>
<title>devtrends.com CAML Encode and Decode</title>
<STYLE>
<!--
.outbox {
padding:10px;
margin:4px;
margin-bottom:15px;
border:1px dashed #9E7760;
background-color:#DBCABF;
}
-->
</STYLE>
</head>
<body style="background-color:#FFFFFF;">
<p style="text-align:center;font-family:verdana;font-size:20px;">sharepoint caml encode and decode</p>
<center>
<?php
if ($_POST['dir'] == "e") {
?><div><?php
echo camlencode($_POST['caml']);
?></div><?php
} elseif ($_POST['dir'] == "d") {
?><div><?php
echo $_POST['caml'];
?></div><?php
}
?>
<form method="post" action="index.php">
<input type="text" name="caml" size="50" />
<select name="dir">
<option value="e"<?php if($_POST['dir'] == "e"){echo "selected";} ?>>Encode</option>
<option value="d"<?php if($_POST['dir'] == "d"){echo "selected";} ?>>Decode</option>
</select>
<input type="submit" value="process" />
</form>
</center>
<p style="text-align:center;font-family:verdana;font-size:12px;">note: the decode utilizes standard HTML rendering and the encode will only change the following characters (", <, >).</p>
<p style="text-align:center;font-family:verdana;font-size:10px;"><a href="http://www.devtrends.com/">a simple service of www.devtrends.com</a></p>
</body>
</html>
<?php
function camlencode($mycamlstr) {
$mycamlstr = str_replace("<", "&lt;", $mycamlstr);
$mycamlstr = str_replace(">", "&gt;", $mycamlstr);
$mycamlstr = str_replace("\"", "&quot;", $mycamlstr);
return $mycamlstr;
}
function camldecode($mycamlstr) {
$mycamlstr = str_replace("<", chr(60), $mycamlstr);
$mycamlstr = str_replace(">", chr(62), $mycamlstr);
$mycamlstr = str_replace(""", chr(34), $mycamlstr);
return $mycamlstr;
}
?>
About the Author

IT is not just a job but also a passion. Everything I have accomplished, both personally and professionally, has been generally entertaining, bordering on fun. Some of my projects, such as working with SharePoint Services workflow actions in Visual Studio or building a custom iSCSI SAN using the OpenSolaris, ZFS and COMSTAR, has been quite rewarding. You may think nerd...I think developing a new trend!