Welcome Guest, Not a member yet? Register   Sign In
XML as a datasource.?
#1

[eluser]rvent[/eluser]
Hello,

Our ERP uses IBM UniData and the version we run does not support connection pooling so we would have to use Red Back Object in order to access our data. I am not familiar with RBO so i want to avoid having to go that route. So here is can i can do.

UniData can generate and XML file with the results from the query
Code:
<?xml version="1.0"?>
<ROOT>
<WP>
  <Team>CHANE</Team>
  <Team_Name>Chane Grant's Product Lines</Team_Name>
  <Assy_Line>ADN</Assy_Line>
  <Line_Desc>ADN assembler</Line_Desc>
  <Wo_Nbr>127416</Wo_Nbr>
  <Customer_Parent>100017250</Customer_Parent>
  <Part_Nbr_Short>46441</Part_Nbr_Short>
  <Date_Sch_Comp>09-11-08</Date_Sch_Comp>
  <Date_Rlse>08-15-08</Date_Rlse>
</WP>
<WP>
  <Team>CHANE</Team>
  <Team_Name>Chane Grant's Product Lines</Team_Name>
  <Assy_Line>ADN</Assy_Line>
  <Line_Desc>ADN assembler</Line_Desc>
  <Wo_Nbr>125256</Wo_Nbr>
  <Customer_Parent>100133094</Customer_Parent>
  <Part_Nbr_Short>61357</Part_Nbr_Short>
  <Date_Sch_Comp>09-11-08</Date_Sch_Comp>
  <Date_Rlse>06-23-08</Date_Rlse>
</WP>
<WP>
  <Team>CHANE</Team>
  <Team_Name>Chane Grant's Product Lines</Team_Name>
  <Assy_Line>ADN</Assy_Line>
  <Line_Desc>ADN assembler</Line_Desc>
  <Wo_Nbr>126140</Wo_Nbr>
  <Customer_Parent>S-299770</Customer_Parent>
  <Part_Nbr_Short>36094</Part_Nbr_Short>
  <Date_Sch_Comp>09-11-08</Date_Sch_Comp>
  <Date_Rlse>07-15-08</Date_Rlse>
</WP>
</ROOT>

How can i use CI to use that XML file as a database..? I want to be able to have some sort of selection based on team and return a JSON to my JavaScript pages...

Possible...?

Any ideas...?

Thanks
#2

[eluser]gRoberts[/eluser]
its possible but all depends on how much functionality you want to have. Do you want to be able to search any/specific columns with part or whole values?
#3

[eluser]madla[/eluser]
I've got the same question.

I have a list of articles in an XML file (an Rss feed).

I want to be able to search the articles based on the meta data e.g. categories.
No updates no changes, just for search purposes.

How would I go about connecting the xml file as a database?

Thanks...martin
#4

[eluser]Crafter[/eluser]
[quote author="madla" date="1221526953"]I've got the same question.
How would I go about connecting the xml file as a database?
[/quote]

That would only be the route if you want to run database queries against the XML file.

In that case, you would want to create a new adapter for xml data sources. Probably more trouble than it is worth.

Otherwise, create a model to read/write the xml files. If you need more than one model reading from xml sources, you might look at implementing an xml library if you don;t have one.
#5

[eluser]Michael Wales[/eluser]
A pretty simple function I have only tested on the del.icio.us API but it seems to be working properly - will convert an XML string into a multi-dimensional array.

Code:
function xml2array($contents, $get_attributes=1) {
    if (!function_exists('xml_parser_create')) {
        show_error('Server does not support xml_parser_create');
    }
    $parser = xml_parser_create();
    xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
    xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
    xml_parse_into_struct( $parser, $contents, $xml_values );
    xml_parser_free( $parser );

    // Empty XML tree...
    if(!$xml_values) return;
        
    $xml_array = array();
    $parents = array();
    $opened_tags = array();
    $arr = array();

    $current = &$xml_array;

    //Go through the tags.
    foreach ($xml_values as $data) {
        unset($attributes,$value);
        extract($data);

        $result = '';
        if ($get_attributes) {
            $result = array();
            if (isset($value)) $result['value'] = $value;
            if (isset($attributes)) {
                foreach( $attributes as $attr => $val) {
                    if ($get_attributes == 1) $result['attr'][$attr] = $val;
                }
            }
        } elseif (isset($value)) {
            $result = $value;
        }

        if ($type == "open") {
            $parent[$level-1] = &$current;
            if (!is_array($current) or (!in_array($tag, array_keys($current)))) {
                $current[$tag] = $result;
                $current = &$current[$tag];
            } else {
                if (isset($current[$tag][0])) {
                    array_push($current[$tag], $result);
                } else {
                    $current[$tag] = array($current[$tag],$result);
                }
                $last = count($current[$tag]) - 1;
                $current = &$current[$tag][$last];
            }
        } elseif ($type == "complete") {
            if (!isset($current[$tag])) {
                $current[$tag] = $result;
            } else {
                if ((is_array($current[$tag]) and $get_attributes == 0) or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) {
                    array_push($current[$tag],$result);
                } else {
                    $current[$tag] = array($current[$tag],$result);
                }
            }
        } elseif ($type == 'close') {
            $current = &$parent[$level-1];
        }
    }
    return($xml_array);
}
#6

[eluser]Bramme[/eluser]
PHP has 3 built in XML parsing classes (if I'm not mistaken). xml_parser being one of them. I guess you should look into those. I know there's one that's pretty easy (read: simple with not so much functions), but I can't think of the name right away.
#7

[eluser]madla[/eluser]
Thanks for the quick responses!

The reason I was thinking db was, that once the file is parsed, I'll have to hit the data constantly for filtering out part and bits.
But I can read it once and cache it on the Application scope assuming there is such a thing in CI (I'm new to CI -- but liking it already).

Thanks again...martin




Theme © iAndrew 2016 - Forum software by © MyBB