Jump to content
xisto Community
Jonnyabc

Putting Xhtml To Good Use Question on how to pull XML data from XHTML with PHP.

Recommended Posts

XHTML is a refined version of HTML and follows the guidelines of XML but is an ordinary web page. JavaScript and PHP allow users to access XML documents. I've recently learned the basics behind XSD (formatting/nesting rules for a specific XML document) and gather that this is the same equivalent of DTD and/or XMNLS.However, I am still at a loss how you can use JavaScript/PHP to pull in data from an XHTML document. I imagine you still use the same XML parsers you would use for an XML (RSS) file, but beyond that, I haven't a clue, but I know it is possible because I have seen it in action.Thanks!

Edited by Jonnyabc (see edit history)

Share this post


Link to post
Share on other sites

Seriously, does nobody have a clue at either what I am asking for, or does it simply not exist? All I'm looking for is a short explanation at what to research this on. If I have the following code:

<html>     ...     <body>          ...          <ul>               <li>1. First</li>               <li>2. Second</li>               <li>3. Third</li>          <ul>          ...     </body>     ...</html>

...how do I retrieve the list items from this?

Share this post


Link to post
Share on other sites

Seriously, does nobody have a clue at either what I am asking for, or does it simply not exist?

This has been the first question you have asked in this topic. You've already hinted about PHP's XML parser and that JavaScript can traverse the DOM, which implies you have a general idea on where you can obtain the corresponding documentation. The documentation on each is available on the internet, many of them bearing examples (especially if we're talking about the PHP documentation).

All I'm looking for is a short explanation at what to research this on. If I have the following code:

<html>     ...     <body>          ...          <ul>               <li>1. First</li>               <li>2. Second</li>               <li>3. Third</li>          <ul>          ...     </body>     ...</html>

...how do I retrieve the list items from this?
If that is the only list, then just navigate the DOM till you run into the list. I know you posted this topic under the PHP forum, but this is more of a job for JavaScript. You can use getElementsByTagName() in JavaScript. If that is not the only unordered list, then you will have a heck of a time distinguishing it from the other lists. You'll have to provide an attribute (generally ID is used, but anything can be used so long as it is unique) that helps distinguish it from other unordered lists. If you use the ID attribute, then you can use getElementById() in JavaScript.

Attempting to parse and traverse the HTML through PHP is much of a chore compared to JavaScript. Always pick JavaScript over PHP when you only need to traverse and manipulate the DOM wherever possible. Only as a last resort should you go with PHP.

Share this post


Link to post
Share on other sites

When using either PHP or Javascript, you have an option of processing XML data using string functions or using an XML or DOM API. Having said that, most PHP scripts use a database to store and retrieve data simply because it makes management easier. Changing the structure of a database table is much easier than having to re-write an XML document, managing data constraints is the responsibility of the database management system rather than the code (though some storage engines do not enforce all constraints), and data replication and backups are some of the key functions of database management systems.XML is quite useful for systems to exchange data simply because it's a plain-text format and does not depend on the endian-ness of systems or on any other proprietary format. It's easy to use for representing data and is (mostly) human-readable.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.