Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    XML for directory structures

    Okay, so I get the concept of XML as a general rule but I've never had to program w/ it up to this point. So I'm confusing the heck out of myself here about what its the proper way to implement something.

    My goal is to create an xml file that defines encodes our electronic file management process. So the required directory structure, file contents and naming procedures for projects. Simply put certain files have be in specific locations w/ certain names.

    So is it better to :
    1. have the xml be structured like the directory: Meaning child directories are subsets w/in the xml data set?
    2. having a singular element for each required file type that describes the relative path from the top most parent?


    In my mind option 1 would be the best bet. Am I correct?
    Code:
    <dir name="xxx">
       <file ref="http://..." name="aaa" record="y" etc. ></file>
       <file ref="http://..." name="bbb" record="n" etc. ></file>
       <file ref="http://..." name="ccc" record="y" etc. ></file>
       <dir name = "yyy">
       </dir>
    <dir>
    Thanks for all the assistance on this.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,691
    Thanks
    25
    Thanked 657 Times in 656 Posts
    I would set up a section based on the project and that section would contain the info for defining your files. Lets say your doing loans for cars, trucks, and motorcycles.
    Code:
    <projects>
    	<project type="car">
    		<dir>yyy</dir>
    		<ref>http://... </ref>  
    		<name>aaa</name>   
    		<record>y</record>
    	</project>
    	<project type="truck">
    		<dir>xxx</dir>
    		<ref>http://... </ref>  
    		<name>bbb</name>   
    		<record>n</record>
    	</project>
    	<project type="motorcycle">
    		<dir>vvv</dir>
    		<ref>http://... </ref>  
    		<name>ccc</name>   
    		<record>y</record>
    	</project>
    </projects>
    You can go directly to the "project type" and retrieve the info.

    Use this code to retrieve the info.:
    PHP Code:
    <?php
    $xml 
    simplexml_load_file("test2.xml");  // If you name the above code file test2.xml

    $project $xml->project;

    for(
    $i 0$i sizeof($project); $i++)
    {
        if(
    $project[$i]->attributes()->type == "truck")  // call this php file and use $_POST to subsitiute for "truck"
        
    {
            echo 
    $project[$i]->dir."<br />";
            echo 
    $project[$i]->ref."<br />";
            echo 
    $project[$i]->name."<br />";
            echo 
    $project[$i]->record."<br />";
        }
    }
    ?>
    Last edited by sunfighter; 11-20-2012 at 07:28 PM. Reason: to add the php for retrieving information

  • Users who have thanked sunfighter for this post:

    Itch (11-20-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the response sunfighter. That points me in the direction I need.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •