Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

simplexml_load_file(3) [php man page]

SIMPLEXML_LOAD_FILE(3)							 1						    SIMPLEXML_LOAD_FILE(3)

simplexml_load_file - Interprets an XML file into an object

SYNOPSIS
SimpleXMLElement simplexml_load_file (string $filename, [string $class_name = "SimpleXMLElement"], [int $options], [string $ns = ""], [bool $is_prefix = false]) DESCRIPTION
Convert the well-formed XML document in the given file to an object. PARAMETERS
o $filename - Path to the XML file Note Libxml 2 unescapes the URI, so if you want to pass e.g. b&c as the URI parameter a, you have to call sim- plexml_load_file(rawurlencode('http://example.com/?a=' . urlencode('b&c'))). Since PHP 5.1.0 you don't need to do this because PHP will do it for you. o $class_name - You may use this optional parameter so that simplexml_load_file(3) will return an object of the specified class. That class should extend the SimpleXMLElement class. o $options - Since PHP 5.1.0 and Libxml 2.6.0, you may also use the $options parameter to specify additional Libxml parameters. o $ns - Namespace prefix or URI. o $is_prefix - TRUE if $ns is a prefix, FALSE if it's a URI; defaults to FALSE. RETURN VALUES
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or FALSE on failure. ERRORS
/EXCEPTIONS Produces an E_WARNING error message for each error found in the XML data. Tip Use libxml_use_internal_errors(3) to suppress all XML errors, and libxml_get_errors(3) to iterate over them afterwards. EXAMPLES
Example #1 Interpret an XML document <?php // The file test.xml contains an XML document with a root element // and at least an element /[root]/title. if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); print_r($xml); } else { exit('Failed to open test.xml.'); } ?> This script will display, on success: SimpleXMLElement Object ( [title] => Example Title ... ) At this point, you can go about using $xml->title and any other elements. SEE ALSO
simplexml_load_string(3), SimpleXMLElement::__construct, "Dealing with XML errors", libxml_use_internal_errors(3), "Basic SimpleXML usage". PHP Documentation Group SIMPLEXML_LOAD_FILE(3)

Check Out this Related Man Page

Test::XML::XPath(3pm)					User Contributed Perl Documentation				     Test::XML::XPath(3pm)

NAME
Test::XML::XPath - Test XPath assertions SYNOPSIS
use Test::XML::XPath tests => 3; like_xpath( '<foo />', '/foo' ); # PASS like_xpath( '<foo />', '/bar' ); # FAIL unlike_xpath( '<foo />', '/bar' ); # PASS is_xpath( '<foo>bar</foo>', '/foo', 'bar' ); # PASS is_xpath( '<foo>bar</foo>', '/bar', 'foo' ); # FAIL # More interesting examples of xpath assertions. my $xml = '<foo attrib="1"><bish><bosh args="42">pub</bosh></bish></foo>'; # Do testing for attributes. like_xpath( $xml, '/foo[@attrib="1"]' ); # PASS # Find an element anywhere in the document. like_xpath( $xml, '//bosh' ); # PASS # Both. like_xpath( $xml, '//bosh[@args="42"]' ); # PASS DESCRIPTION
This module allows you to assert statements about your XML in the form of XPath statements. You can say that a piece of XML must contain certain tags, with so-and-so attributes, etc. It will try to use any installed XPath module that it knows about. Currently, this means XML::LibXML and XML::XPath, in that order. NB: Normally in XPath processing, the statement occurs from a context node. In the case of like_xpath(), the context node will always be the root node. In practice, this means that these two statements are identical: # Absolute path. like_xpath( '<foo/>', '/foo' ); # Path relative to root. like_xpath( '<foo/>', 'foo' ); It's probably best to use absolute paths everywhere in order to keep things simple. NB: Beware of specifying attributes. Because they use an @-sign, perl will complain about trying to interpolate arrays if you don't escape them or use single quotes. FUNCTIONS
like_xpath ( XML, XPATH [, NAME ] ) Assert that XML (a string containing XML) matches the statement XPATH. NAME is the name of the test. Returns true or false depending upon test success. unlike_xpath ( XML, XPATH [, NAME ] ) This is the reverse of like_xpath(). The test will only pass if XPATH does not generates any matches in XML. Returns true or false depending upon test success. is_xpath ( XML, XPATH, EXPECTED [, NAME ] ) Evaluates XPATH against XML, and pass the test if the is EXPECTED. Uses findvalue() internally. Returns true or false depending upon test success. set_xpath_processor ( CLASS ) Set the class name of the XPath processor used. It is up to you to ensure that this class is loaded. In all cases, XML must be well formed, or the test will fail. SEE ALSO
Test::XML. XML::XPath, which is the basis for this module. If you are not conversant with XPath, there are many tutorials available on the web. Google will point you at them. The first one that I saw was: <http://www.zvon.org/xxl/XPathTutorial/>, which appears to offer interactive XPath as well as the tutorials. AUTHOR
Dominic Mitchell <cpan2 (at) semantico.com> COPYRIGHT AND LICENSE
Copyright 2002 by semantico This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2009-07-02 Test::XML::XPath(3pm)
Man Page