|
-
Apr 12th, 2007, 09:57 AM
#1
Thread Starter
Frenzied Member
Get value from xml file.....fast
First off, I'm new to php, soo..... (yes, I'm studying, but did not get to xml yet)
This is for an experiment I'm busy with re multilingual sites. I want to figure the best performing method, and then create a sample solution for all to share.
For this specific test, I want to store text in xml files like this:
Code:
<text id="lblHome">
<en>Home</en>
<ja>家</ja>
<zh>家庭</zh>
<description>Link to the home page</description>
</text>
<text id="lblWork">
<en>Work</en>
<ja>仕事</ja>
<zh>工作</zh>
<description>Link to the Work for Us Page</description>
</text>
in my code I want to be able to call a function to get the text like this:
Code:
<h1><?php GetText('lblHome'); ?></h1>
In an included file a function like this (pseudo code):
Code:
function GetText(value) {
$lang = get the current language from session
load xml file
$text = get value of X node for given value parent node (X will be 'en', 'ja', 'zh')
return $text;
}
What I would like to know is the best way to only read a value from an xml file quickly. From the code I looked at earlier, it seems one loop through the xml file...this does not sound right to me (but then, I had a quick look)
-
Apr 16th, 2007, 07:32 AM
#2
Hyperactive Member
Re: Get value from xml file.....fast
http://pear.php.net/package/XML_Parser
try pear? Natively written c library to parse xml using php extention. You have to get this installed by server admin if you are not.
There is the http://www.php.net/xslt method which requires you to have sabletron support on your server. You need sabletron installed in php.
Also, you can do it client side with javascript. You can do a nice AJAX call and get the same basic functionality using a bit of dHTML.
Just google there is plenty of examples.
The last method that I know of is the one you describe. You can click the link on my signature for an example for parsing ATOM. The reason why, you do it this way is it basically allows your to parse a XML file without having an special libraries like PEAR or sabletron installed. All you need is a base install of PHP 4.x. This is optimal any code that needs to run a lot of different install bases of PHP, which why i choose to write my parse in that method, because there is a lack ATOM parser that could actually parse the ATOM document without sabletron.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|