示例#1
0
文件: index.php 项目: Kervinou/OBM
function create_xml($entity,$root_node,$name_entity,$multisearch=false){
  $xml_doc = new DOMDocument('1.0', 'UTF-8') ;
  
  $head_node = $xml_doc->createElement($root_node) ;
  $xml_doc->appendChild($head_node) ;
  
  foreach($entity as $key => $data){
    if($multisearch){
      // create entity node
      $entity_node = $xml_doc->createElement($name_entity) ;
      $head_node->appendChild($entity_node) ;
      // foreach data, create xml node, add it to contact node
      foreach ($data as $name => $value) {
        $new_node = $xml_doc->createElement($name, utf8_encode(htmlspecialchars($value, ENT_COMPAT))) ;
        $entity_node->appendChild($new_node) ;
      }
    } else {
      foreach ($data as $name => $value) {
        create_listing_node(&$xml_doc, $head_node, $name_entity, $value) ;
      }
    }
  }
  // return xml doc
  $xml_string = $xml_doc->saveXML() ;
  return $xml_string ;
}
示例#2
0
文件: contact.php 项目: Kervinou/OBM
/**
 * get_contact_list
 *
 * @return string XML representation of contact listing
 */
function get_contact_list() {
  // get sql ids
  $ids = array() ;
  $ids = get_contact_list_ids() ;
  
  // if no ids
  if (count($ids) == 0) {
    return ;
  }

  // else
  // create xml doc
  $xml_doc = new DOMDocument('1.0', 'UTF-8') ;

  // create listing node
  $listing_node = $xml_doc->createElement('listing') ;
  $xml_doc->appendChild($listing_node) ;

  // foreach id, create xml node and add it to doc
  foreach($ids as $id) {
    $id_node = create_listing_node(&$xml_doc, $listing_node, 'contact', $id) ;
  }

  // return xml doc
  $xml_string = $xml_doc->saveXML() ;
  return $xml_string ;
}
示例#3
0
文件: company.php 项目: Kervinou/OBM
/**
 * get_company_detail
 *
 * return string XML representation of one company (company fields and company's contacts listing)
 */

function get_company_detail() {
  // get sql datas
  $datas = get_company_detail_by_id($_GET['entity_id']) ;
  $contacts = get_contact_list_ids($_GET['entity_id']) ;

  // if no datas, return
  if (count($datas) == 0) {
    return ;
  }

  // else
  // create xml doc
  $xml_doc = new DOMDocument('1.0', 'UTF-8') ;

  // create company node
  $entity_node = $xml_doc->createElement('company') ;
  $xml_doc->appendChild($entity_node) ;

  // foreach data, create xml node, add it to company node
  foreach ($datas as $data) {
    foreach ($data as $name => $value) {
      $new_node = $xml_doc->createElement($name, utf8_encode(htmlspecialchars($value, ENT_COMPAT))) ;
      $entity_node->appendChild($new_node) ;
    }
  }

  // create contacts node
  $contacts_node = $xml_doc->createElement('company_contacts') ;
  $entity_node->appendChild($contacts_node) ;

  // foreach contact ,create xml node, add it to contacts node
  if (count($contacts) != 0) {
    foreach($contacts as $contact_id) {
      $id_node = create_listing_node(&$xml_doc, $contacts_node, 'contact', $contact_id) ;
    }
  }

  // return xml doc
  $xml_string = $xml_doc->saveXML() ;
  return $xml_string ;
}