Write Louder! (How To Write …?)

Useful Writing Books, Articles, Software

Php Write Xml Attribute

without comments

How do I get php to do the following with xml?

The xml document:















What I want the script to do is to find an element in the document above, get the values of "anotherattribute" from elements with the same name, and Write the data from each of the files in "anotherattribute" in to a file "attributefiles.txt" with the only piece of data the user inputs is the attribute name.

For example, if someone enters "element_1", I want the script to return "attributefiles.txt" with the data from "value2.txt" and "value3.txt" in the file.

I'm going to use the XMLReader class which is present in PHP 5. I am assuming the element chosen by the viewer is stored in the variable $element.

I am going to collect all $element nodes and record all attributes from those nodes with the name 'anotherattribute'.

$xml = new XMLReader();
$xml->open("path/to/doc.xml");
while($xml->read()) {
if($xml->name == $element) {
if($xml->moveToAttribute( 'anotherattribute' )) {
$data .= $xml->value;
}
}
}
$xml->close();

$fp = fopen('attributefiles.txt', 'a');
flock($fp, 2);
fwrite($fp, $data);
fclose($fp);
?>

Getting Started with the Google Data PHP Client Library




Compare............................................................................................


Pro Php Xml And Web Services


Pro Php Xml And Web Services


$63.37


No Synopsis Available

Php Cookbook


Php Cookbook


$64.88


In this book for web programmers using PHP, the authors address frequently encountered challenges in the form of approximately 250 "recipes"--each a complete PHP template for achieving a specific result. The recipes are easily navigated and grouped by functions such as dates and times, graphics, error management, security and encryption, and web automation. Some specific tasks include finding and fixing parse errors; drawing lines, rectangles and polygons; getting and putting up files with FTP; and processing variable-length text fields. Updates in this second edition include new sections on processing XML, and building web services using PHP. Annotation )2006 Book News, Inc., Portland, OR (booknews.com)

Programming PHP


Programming PHP


$19.09


<div><p><i>Programming PHP</i>, 2nd Edition, is the authoritative guide to PHP 5 and is filled with the unique knowledge of the creator of PHP (Rasmus Lerdorf) and other PHP experts. When it comes to creating websites, the PHP scripting language is truly a red-hot property. In fact, PHP is currently used on more than 19 million websites, surpassing Microsoft's ASP .NET technology in popularity. Programmers love its flexibility and speed; designers love its accessibility and convenience. </p> <p> As the industry standard book on PHP, all of the essentials are covered in a clear and concise manner. Language syntax and programming techniques are coupled with numerous examples that illustrate both correct usage and common idioms. With style tips and practical programming advice, this book will help you become not just a PHP programmer, but a <i>good</i> PHP programmer. <i>Programming PHP, Second Edition</i> covers everything you need to know to create effective web applications with PHP. Contents include:</p> <ul><li>Detailed information on the basics of the PHP language, including data types, variables, operators, and flow control statements</li> <li>Chapters outlining the basics of functions, strings, arrays, and objects</li> <li>Coverage of common PHP web application techniques, such as form processing and validation, session tracking, and cookies</li> <li>Material on interacting with relational databases, such as MySQL and Oracle, using the database-independent PEAR DB library and the new PDO Library</li> <li>Chapters that show you how to generate dynamic images, create PDF files, and parse XML files with PHP</li> <li>Advanced topics, such as creating secure scripts, error handling, performance tuning, and writing your own C language extensions to PHP</li> <li>A handy quick reference to all the core functions in PHP and all the standard extensions that ship with PHP</li> </ul><p> Praise for the first edition: </p> <p> "If you are just getting into the dynamic Web development world or you are considering migrating from another dynamic web product to PHP, <i>Programming PHP</i> is the book of choice to get you up, running, and productive in a short time." </p> <p>--Peter MacIntrye, eWeek</p> <p> "I think this is a great book for programmers who want to start developing dynamic websites with PHP. It gives a detailed overview of PHP, lots of valuable tips, and a good sense of PHP's strengths." </p> <p>--David Dooling, Slashdot.org </p></div>

.........................................................................................................


Written by admin

March 1st, 2011 at 11:27 am

Leave a Reply