Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing XML with XPath..

Status
Not open for further replies.

Tokhra

Programmer
Oct 1, 2003
134
ES
Hey all,

Im attempting to parse the following xml schema:

Code:
<language name="Spanish" short="Es">
	<text key="Hello">
		Hola
	</text>

        <text key="House">
                Casa
        </text>
</language>

so basically theres one <language> which contains lots of <text> elements, now so far I have this:

Code:
function getText($key)
		{
			$doc = new DOMDocument();
			
			$doc->load($this->_file);
			
			$xpath = new DOMXPath($doc);
			
			$nodelist = $xpath->query("language/text[@key='$key']");
			
			$node = $nodelist->item(0);
			
			// Return inner text from node.
		}

Which, when I call GetText('Hello'); for example, should return 'Hola', except im not sure how to retrieve the inner text for a DomNode ?

Also I havent tested that code yet, so if anyone sees anything wrong please tell me,

Thanks very much,
Matt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top