XML::LibXML extracting a value

This should be incredibly simple. I've been using findnodes quite happily for a while now, but if I just need to extract a single value, I'm not sure it is that efficient. Consider the following xml document:

<document>
   <page>
     <pagenumber>1</pagenumber>
     <detail>bla bla bla</detail>
   </page>
</document>

surely, I chould be able to say something like: $pageno=$doc->"document/page/pageno"; I should end up with a 1 in $pageno? What is the exact syntax to obtain the correct result? Is there some sensible documentation with examples somewhere? Many thanks,

Answers


You can use the built-in PHP class SimpleXMLElement like this;

<?php

  $xml = "
    <document>
       <page>
         <pagenumber>1</pagenumber>
         <detail>bla bla bla</detail>
       </page>
    </document>
  ";

  $sxe = new SimpleXMLElement($xml);
  $pageno = $sxe->page->pagenumber;

  echo $pageno;

?>

That will give you your desired result: 1


Need Your Help

Application boost::thread stuck on mutex lock when compiled for ARM running on BeagleBone Black

c++ locking cross-compiling boost-thread beagleboneblack

I am currently working on a C++ app that runs on my PC just fine and I want to make it work on a BeagleBone Black on which I have already installed a Debian Wheezy.

Unit testing Grails domains that (over?) extend a base class that uses services

unit-testing grails inheritance groovy gorm

So, I have a base class that I want to extend most (but not all) of my domain classes from. The goal is that I can add the six audit information columns I need to any domain class with a simple ext...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.