XML
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsWeb Design & DevelopmentXML

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old October 29th, 2009, 10:00 AM
Admin Admin is offline
Developer Shed
Click here for more information.
 
Join Date: Jun 2007
Posts: 20,338 Admin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 23
Parsing XML Documents in PHP

All XML parsing is done by SimpleXML internally using the DOM parsing model.

There are no special calls or tricks you need to perform to parse a document. The

only restraint is that the XML document must be well-formed, or SimpleXML will

emit warnings and fail to parse it. Also, while the W3C has published a recommended

specification for XML1.1, SimpleXML supports only version 1.0 documents.

Again, SimpleXMLwill emit a warning and fail to parse the document if it encounters

an XML document with a version of 1.1.

All objects created by SimpleXML are instances of the SimpleXMLElement class.

Thus, when parsing a document or XML string, you will need to create a new

SimpleXMLElement; there are several ways to do this. The first two ways involve the

use of procedural code, or functions, that return SimpleXMLElement objects. One

such function, simplexml_load_string(), loads an XML document from a string,

while the other, simplexml_load_file(), loads an XML document from a path. The

following example illustrates the use of each, pairing file_get_contents() with

simplexml_load_string(); however, in a real-world scenario, it would make much

more sense to simply use simple_xml_load_file():





// Load an XML string

$xmlstr = file_get_contents(’library.xml’);

$library = simplexml_load_string($xmlstr);

// Load an XML file

$library = simplexml_load_file(’library.xml’);



Since it was designed to work in an object-oriented environment, SimpleXML also

supports an OOP-centric approach to loading a document. In the following example,

the first method loads an XML string into a SimpleXMLElement, while the second

loads an external document, which can be a local file path or a valid URL.





// Load an XML string

$xmlstr = file_get_contents(’library.xml’);

$library = new SimpleXMLElement($xmlstr);

// Load an XML file

$library = new SimpleXMLElement(’library.xml’, NULL, true);



Note here that the second method also passes two additional arguments to

SimpleXMLElement’s constructor. The second argument optionally allows the ability

to specify additional libxml parameters that influence the way the library parses the

XML. It is not necessary to set any of these parameters at this point, so we left it to

NULL. The third parameter is important, though, because it informs the constructor

that the first argument represents the path to a file, rather than a string that contains

the XML data itself.

Read the full article here: Parsing XML Documents in PHP

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentXML > Parsing XML Documents in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek