C++ Learning Community Forum
September 04, 2010, 04:45:10 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Parsing and using data from a xml schema- where to start?  (Read 606 times)
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1238



View Profile
« on: February 01, 2010, 07:34:23 PM »

There's an xml schema at http://anubis.iseclab.org/xml_schema/report_version_3.1/schema.xsd that describes the format of the xml files I'm wanting to parse and get data from. its important to know what sort of tags to look for, as some reports need to use tags that others dont need, so its not like I can just look for certain tags really. Anyone know much about this sort of thing? I googled a little, and couldnt find much about what I actually have to do. I'll google more later when I have more time. I'm dealing with this stuff in Php , just an fyi.

 Huh
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1238



View Profile
« Reply #1 on: February 02, 2010, 11:32:50 PM »

heres what i have so far  Roll Eyes
Code
GeSHi (php):
<?php
$dom=new DOMDocument();
$dom->load('http://anubis.iseclab.org/xml_schema/report_version_3.1/schema.xsd');
 
 foreach($dom->getElementsByTagName('element') as $element)
 {
  echo $element->getAttribute('name')."<br>";
  echo "&nbsp;&nbsp;&nbsp;".$element->getAttribute('ref')."<br>";
   /*if($element->hasChildNodes())
{
// echo "has child nodes<br>";
echo " ".$element->getAttribute('ref');
}*/

 }
?>
Created by GeSHI 1.0.7.18
all i really am needing to do is figure out which tags are used where in the xml output http://anubis.iseclab.org/index.php?action=result&task_id=18b9cf596ff6959e4e54ea3e4a12ce87c&format=xml the tags that are used differ depending on what data is present, however the schema contains information about where all the tags are to be expected (if i'm understanding correctly)
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
C-Man
Does anyone even read this ?
Global Moderator
Dr. of C++ology
*****
Posts: 988



View Profile WWW
« Reply #2 on: February 02, 2010, 11:55:33 PM »

I don't see a point in using schema unless you're doing one of the following things
a) validating an xml message for the right structure
b) writting code that dynamically adapts to changes instructure (how do you that have no fucking clue cause you can't know what changed into what and what should it mean, code can't read specifications you know...)

otherwise the structure will be pretty much the same all the time and you can assume it'll work for a while , and if it breaks you fix it with an updated one

schemas are meant for validation and there is not much other use for them
Logged

ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1238



View Profile
« Reply #3 on: February 03, 2010, 05:20:38 AM »

Yeah i was going for "b" i guess. I was kind of picturing something like an array of element names which would be fed into a loop and then store the data into separate arrays based on tag name, and i could do something with them later on. Undecided I suppose I could just use the schema as sort of a guide to help me program so i know what could possibly be in the xml reports that i am wanting to parse
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
myork
Global Moderator
C++ guru
*****
Posts: 1147


View Profile
« Reply #4 on: February 03, 2010, 07:46:03 AM »

You need to learn about XPath.

http://www.php.net/manual/en/simplexmlelement.xpath.php


Basically it allows you to specify a path to an XML element.
It will return you an array of nodes that match the expression:

Code:
# $xml is an xml document (see the link above).
$xml->xpath('analysis/analysis_subject/activities/file_activities/file_modified[@name="C:\ntsvcs, Flags: Named pipe"]');

The above means find the 'file_modified' nodes in the xml document that are nested like this:
Code:

<STUFF>
    <analysis>
       <analysis_subject>
          <activities>
             <file_activities>
                <file_modified name="C:\ntsvcs, Flags: Named pipe">  <!-- This node -->
                </file_modified>
             </file_activities>
          </activities>
       </analysis_subject>
    </analysis>
</STUFF>
Where the 'file_modified' node has an attribute named 'name' with the value "C:\ntsvcs, Flags: Named pipe"
« Last Edit: February 03, 2010, 07:48:42 AM by myork » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!