digitalgod Posted March 17, 2008 Share Posted March 17, 2008 hey guys, I was just wondering if there was a way to clean up the code in an xml file. Right now I'm using SimpleXML to add child nodes and whenever one gets appended it doesn't add a new line nor an indent, so it ends up looking something like this <book>foo</book><book>bar</book> Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/ Share on other sites More sharing options...
soycharliente Posted March 17, 2008 Share Posted March 17, 2008 Find/replace all? Maybe a preg_match or something. </book><book> with </book>\n<book> Dreamweaver does that too when you try to use the code tidy. I hate it. It does it with <table>. Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-494321 Share on other sites More sharing options...
effigy Posted March 17, 2008 Share Posted March 17, 2008 tidy Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-494335 Share on other sites More sharing options...
digitalgod Posted March 17, 2008 Author Share Posted March 17, 2008 I actually did try tidy but it didn't seem to do anything to the code... and libtidy is already installed on the server this is what I tried, after writing to an xml file $tidy_options = array( 'input-xml' => true, 'output-xml' => true, 'indent' => true, 'indent-cdata' => true, 'wrap' => false, ); $tidy = new tidy(); $tidy->parseFile('file.xml', $tidy_options); $tidy->cleanRepair(); Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-494362 Share on other sites More sharing options...
digitalgod Posted March 18, 2008 Author Share Posted March 18, 2008 is there something else I should be doing in order for tidy to work? Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-494959 Share on other sites More sharing options...
effigy Posted March 18, 2008 Share Posted March 18, 2008 I thought it was supposed to reformat the document. How does the output compare to the input? Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-494985 Share on other sites More sharing options...
digitalgod Posted March 18, 2008 Author Share Posted March 18, 2008 it's actually exactly the same, nothing changed that's why I'm wondering if I did anything wrong Quote Link to comment https://forums.phpfreaks.com/topic/96592-cleaning-up-an-xml-file/#findComment-495127 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.