Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-19-2012, 09:36 PM   PM User | #1
Itch
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Itch is an unknown quantity at this point
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.
Itch is offline   Reply With Quote
Old 11-20-2012, 05:08 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,366
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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 06:28 PM.. Reason: to add the php for retrieving information
sunfighter is online now   Reply With Quote
Users who have thanked sunfighter for this post:
Itch (11-20-2012)
Old 11-20-2012, 06:49 PM   PM User | #3
Itch
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Itch is an unknown quantity at this point
Thanks for the response sunfighter. That points me in the direction I need.
Itch is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:20 AM.


Advertisement
Log in to turn off these ads.