Re: recursive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2010-07-18 at 09:49 +0430, shahrzad khorrami wrote:

> hi all :)
> here is a xml file:
> 
> <directive>
>    <rule>
>       <rules>
>              <rule>  </rule>
>              <rule>  </rule>
>       </rules>
>    </rule>
> </directive>
> 
> <directive>
>    <rule>
>       <rules>
>              <rule>  </rule>
>              <rule>  </rule>
>       </rules>
>    </rule>
> </directive>
> .
> .
> .
> .....
> I have a xml file with a name for example(test.xml)..
> and 3 tables of database, (group,directives,rules)
> group is for recording the name of the opened xml file,  directives is for
> storing the attributes of directive tag and rules is for 'rule' tag's
> attributes.
> 
> I know I must use of recursive function.. but how? first read name of the
> xml file and store it in group table, then the content of the file and fill
> the directive and rules table...
> 
> 
> <directive  .*... attrs go to directives table..*.>
>    <rule * ...attrs go to rules table...*.>
>       <rules * ..no attrs.*.>
>              <rule   *...attrs go to rules table...*.>  </rule>
>              <rule  *...attrs go to rules table..*..>  </rule>
>       </rules>
>    </rule>
> </directive>
> 
> 
> how to implement it in php?
> 
> Thanks,
> Shahrzad


I don't think a recursive function is what you need here, that's
something which has to call itself over and over.

I assume there may be multiple xml files you need to parse?

What you need is a series of nested loops. The first one loops through
the list of xml filenames you need to parse (you can get this list from
a directory listing if you need), the second goes through each
<directive> tag, the third through the <rule> tags.

The attributes of each tag can be pulled out quite easily. Are these a
list of known attributes, or unknown? If you know what they are, you can
hard-code retrieving their values, but if not, another loop will be able
to fetch these out for you.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux