CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   XML (http://www.codingforums.com/forumdisplay.php?f=3)
-   -   Comparing attributes? (http://www.codingforums.com/showthread.php?t=250361)

Locked 02-01-2012 08:19 AM

Comparing attributes?
 
Code:

<?xml version="1.0" encoding="utf-8"?>
<root>
<page file="register.php">
<title>Register</title>
<username>Username:</username>
<password>Password:</password>
<password2>Retype Pass:</password2>
<email>Email:</email>
</page>

<page file="login.php">
<username>Example</username>
<password>Pass</password>
</page>
</root>

Code:

xmlhttp.open("GET","../xml/en/register.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("username").innerHTML = xmlDoc.getElementsByTagName("username")[0].childNodes[0].nodeValue;

What im wanting to do is create one XML file per language the "file" attribute would be used so that if i have a duplicate XML tag i would be able to select only the tags within say register.php

Im new to XML/JS but in a nutshell i want to:
Select/jump to a certain tag
Pull all the data from that tag only

I could use xmlDoc.getElementsByTagName("username")[0] (register.php) and xmlDoc.getElementsByTagName("username")[1] (login.php) but thats not very practical when adding/deleting pages later

Is this the proper way to do this or should i have a xml file for each page
(en_register.xml
en_login.xml
fr_register.xml
fr_login.xml etc...)

Sorry if i haven't explained this well

theghostofc 02-01-2012 11:57 AM

hii Locked

You can create one XML for this purpose like:
<?xml version="1.0" encoding="utf-8"?>
<languages>
<language name="en">
<pages>
<page file="register.php">
...
</page>
<page file="anotherfile.php">
...
</page>
</pages>
</language>
<language name="fr">
<pages>
<page file="fr_register.php">
...
</page>
<page file="fr_anotherfile.php">
...
</page>
</pages>
</language>
</languages>

This would help you manage pages and languages:
- To add/remove a language simply add/remove a <language> tag in the XML
- Similar for the page

Hope this helps!

Cheers


All times are GMT +1. The time now is 08:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.