NITF2node-module or code-bits?

Events happening in the community are now at Drupal community events on www.drupal.org.
johsw@drupal.org's picture

Hi.

Do any of you guys have a module or parts of a module or just some codebits to do NITF to node parsing and insertion? I that case, I would really like to have a look. I'm considering doing my own from scratch, but a little snippet to get me going would be really cool.

Best,
/J.

Comments

hold on a week or so

victorkane's picture

Will have something soon which parses a series of NewsML URLs and stuffs them into CCK created special article nodes (with meta data, etc.)! You should be able to modify that for NITF.

If you are in a bigger hurry than that, contact me via the Contact Form, and I will let you know what I am doing and we can work together.

Victor Kane
http://awebfactory.com.ar

interesting

bertboerland's picture

would you mind sharing any progress here?

bert boerland

--

bert boerland

No progress...

johsw@drupal.org's picture

So far I've tried parsing our nift-files. Unfortunately our NITF-use is really not stanard-compliant, so I have to do some "ugly" hacking. Now I'm gonna try using node_save to insert the parsed xml.

Best,
/Johs.

to bert and joshw, see above for some code snippets

victorkane's picture

Just a start, will clean up and drupalize shortly...

Victor Kane
http://awebfactory.com.ar

OK, bits it is!

victorkane's picture

Well, got some pieces on the floor for the first iteration of an NITF oriented import script (it all works, but nothing useful yet, I hope soon).

Tasks for first iteration:

  1. Download famous nitf "fishing" example from http://www.nitf.org/IPTC/NITF/3.2/examples/nitf-fishing.xml
  2. Parse it.
  3. Make CCK content type, with the fields.
  4. Script to import the NITF data into CCK. Here is a script to import into CCK from a cvs file, for example: http://groups.drupal.org/node/2197#comment-5840
    (it is meant to be executed like update.php, based on some of Moshe's devel module scripts)(Sorry about the Spanish).

What I have done up till now (see below for code):

  1. Got the nitf-fishing.xml file.
  2. Parsed it two ways (using PHP 5):
    a. With the Pear XML_NITF package at http://pear.php.net/package/XML_NITF as suggested by Yelvington
    b. With SimpleXML functions at http://www.php.net/simplexml
    Really cool is using the xpath capabilities!
    c. With PHP 4 I had used the Pear unserializer, quick example at http://www.sitepoint.com/article/xml-php-pear-xml_serializer/3 , altho I do have some working examples of this, if anyone wants them. As suggested by Yelvington for PHP 4 http://pear.php.net/package/XML_Serializer/

That's it. In the next few days I will have tasks 3 and 4, and will post.

Here is the code (based on the example in the code, but I wanted to actually get it working):

a. With the Pear XML_NITF package on the nitf-fishing.xml file (adjust ini_set params for your setup)(stand-alone php):

<?php
ini_set
("include_path", '/usr/share/php/' . PATH_SEPARATOR . ini_get("include_path"));
require_once
'XML/NITF.php';

$nitf = new XML_NITF();
$nitf->setInputFile('nitf-fishing.xml');
$xResult = $nitf->parse();
echo
$nitf->getHeadline();
echo
$nitf->getByline();
?>

b. With SimpleXML (stand alone php which generates stand alone html page):

<?php
// set name of XML file
$file = "nitf-fishing.xml";
// load file
$nitf = simplexml_load_file($file) or die ("Unable to load XML file!");
?>

<html>
  <head>
  <title><?php print $nitf->head->title ?></title>
    <meta content="">
    <style></style>
  </head>
  <body>

  <h3><?php print $nitf->head->title ?></h3>
  <h1><?php
    $hl1
= $nitf->xpath('//hl1');
    if (
hl1) {
      print
$hl1[0];
    }
 
?>
</h1>
  <h3><?php
    $hl2
= $nitf->xpath('//hl2');
    if (
hl2) {
      print
$hl2[0];
    }
 
?>
</h2>
<?php
 
// just to show off a little nitty-gritty
 
foreach ($nitf->xpath('//tobject[@*]') as $tobject) {
    print
'<hr/>';
    print
'<hr/>';
    foreach (
$tobject->attributes() as $key => $value) {
      print
'<p>' . 'attribute for tobject => ' . $key . ' = ' . $value . '</p>';
    }
   
$children = simplexml_load_string($tobject->asXML());                   <<< cool tip from php doc site
   
foreach ($children->xpath('tobject.subject[@*]') as $child) {
    print
'<hr/>';
      foreach (
$child->attributes() as $attr_name => $attr_value) {
        print
'<p>'  . $attr_name . ' = ' . $attr_value . '</p>';
      }
    }
    print
'<hr/>';
    print
'<hr/>';
  }


?>

  </body>
</html>

Musings on how to pretend procedural php code can do what xsl does:

// whatever is recursive can be iterative with a case structure
// so the algorithm is to get the children; then for each child
// call a function that either does something specific (concatenates to output)
// or gets its children and calls the same function recursively

The hard part is going to be making this universal. The best hope will be to "extend" NITF to NewsML for what I will be needing, but that will come with refactoring later on.

Anyway, will be posting something cleaner shortly. Something based on a CCK generated fieldset, so when you hit enter it takes a URL you put in and takes and parses that. But that's just for show, since most work will be batch oriented, like the above import script.

Victor Kane
http://awebfactory.com.ar

NITF progress

moshe weitzman's picture

I'm looking at an NITF => Drupal project so any code people can share would be much appreciated.

FeedAPI parser for

Newspapers on Drupal

Group organizers

Group categories

Topics - Newspaper on Drupal

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: