nothing500 Posted May 26, 2009 Share Posted May 26, 2009 This might be possible with "DOMDocument::saveHTML()", but I'd like to get by with "SimpleXML" if possible. I can output something almost as I want it with "asXML()", but that leaves me with those darn opening and closing tags from the XML element, when I just want the stuff inside the element. I tried looping through the child nodes with "children()". $xml = '<tag>This is <em>some of</em> my content.</tag>'; $content = new SimpleXMLElement($xml); echo $content->asXML(); // ACTUAL OUTPUT: <tag>This is <em>some of</em> my content.</tag> // DESIRED OUTPUT: This is <em>some of</em> my content. This seems like it should be easy. Anyone know? Link to comment https://forums.phpfreaks.com/topic/159732-solved-how-to-write-the-inner-html-of-an-xml-element/ Share on other sites More sharing options...
nothing500 Posted May 26, 2009 Author Share Posted May 26, 2009 Ok, SimpleXML doesn't notice plain text nodes (http://devzone.zend.com/node/view/id/688). So, I need to serialize a DOMNode so that I'm getting the XML version of the node and not it's text content. Anybody know how to do this? Link to comment https://forums.phpfreaks.com/topic/159732-solved-how-to-write-the-inner-html-of-an-xml-element/#findComment-842676 Share on other sites More sharing options...
nothing500 Posted May 26, 2009 Author Share Posted May 26, 2009 Just found this: XMLReader::readInnerXML... don't know anything about it, but I'm checking it out. Maybe someone's heard of this? Link to comment https://forums.phpfreaks.com/topic/159732-solved-how-to-write-the-inner-html-of-an-xml-element/#findComment-842683 Share on other sites More sharing options...
nothing500 Posted May 26, 2009 Author Share Posted May 26, 2009 Hallelueigah! .. that's a hard word to spell XMLReader::innerXML() is the answer! If you're having difficulty reading XML documents, have a look at XMLReader, PHP's recent pull-based XML parser for a very THOROUGH way of traversing your XML data. You'll need the "libxml" extension active, which is active on PHP >= 5.1 by default. Works like this: $reader = new XMLReader(); $reader->XML($some_xml_element); $reader->next(); echo $reader->readInnerXML(); Thanks, me Link to comment https://forums.phpfreaks.com/topic/159732-solved-how-to-write-the-inner-html-of-an-xml-element/#findComment-842761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.