// XPATH FUNCTION
function getNodes(£myDoc,£myStr) {
£myPath=new DOMXPath(£myDoc);
£myPath->registerNamespace('dnd4e','http://www.wizards.com/default.asp?x=dnd/');
£myResult=array();
£myNodes=£myPath->query(£myStr);
foreach(£myNodes as £node){
array_push(£myResult,£node);
}
return £myResult;
}
// MAIN SCRIPT
£iOS="<?xml version="1.0" encoding="UTF-8"?>"; // The output XML
£iOS.="<?xml-stylesheet type="text/xsl" href="style.xslt"?>"; // Link the XSLT file
£iOS.="<party>";
£iXML=new DOMDocument();
£iCharacter=array(/* SUPPOSE TO HAVE A LIST OF YOUR CHARACTERS' IDs HERE... */)
foreach(£iCharacter as £cid){
£iXML->load("path/to/character{£cid}.dnd4e"); // Suppose you saved the character builder's file like character0.dnd4e, character1.dnd4e, and so on...
// Now you just need to target the right tag on the .dnd4e file...
// For example choose the Stat tag
£iNodes=getNodes(,"/D20Character/CharacterSheet/StatBlock/Stat");
foreach(£iNodes as £node){
switch(strtolower(£node->getAttribute('name'))){
case 'strength':
£iOS.="<ability name="str">".£node->getAttribute('value')."</ability>";
break;
case 'constitution':
£iOS.="<ability name="con">".£node->getAttribute('value')."</ability>;
break;
case 'dexterity':
£iOS.="<ability name="dex">".£node->getAttribute('value')."</ability>;
break;
case 'intelligence':
£iOS.="<ability name="int">".£node->getAttribute('value')."</ability>;
break;
case 'wisdom':
£iOS.="<ability name="wis">".£node->getAttribute('value')."</ability>;
break;
case 'charisma':
£iOS.="<ability name="cha">".£node->getAttribute('value')."</ability>;
break;
//and so on for every Stat tag you would like to read...
}
// Redo for other nodes to fetch informations from other tags (like powers)
}
}
£iOS.="</party>";
header('content-type: text/xml');
print £iOS;