Advertisement

08.27.2008 at 01:07PM PDT, ID: 23683379 | Points: 500
[x]
Attachment Details

Slice XML Document - PHP, XPath, Simplexml

Asked by chrisdpucci in PHP Scripting Language

Hey guys,

I have a question about what I thought would be a simple task that has turned out to be more complicated than expected.

Basically I'm trying to slice an XML fragment from a larger XML document  using xpath and then use that to create a new simplexml element. Sounds super but what I've been trying isn't working.

The trouble I seem to be having is that the result of an xpath query over a simplexml object is an array of elements and values which is fine but not what I need especially since the attributes are not preserved.

Here is some psuedo-code to pass on the basic idea of what I am wanting to do and if you can provide any help, I'd greatly appreciate it:

object  = create simplexml object from source xml
slice = object->xpath(some xpath query)
result = slice as xml rather than an array

If this can't easily be done with simplexml and there is a better way to get the results I'm after, please let me know.

Thanks,

Chris

Start Free Trial
 
 
[+][-]08.28.2008 at 03:18AM PDT, ID: 22333216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628