File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace WsdlToPhp \PackageBase ;
4+
5+ class Utils
6+ {
7+ /**
8+ * Returns a XML string content as a DOMDocument or as a formated XML string
9+ * @uses \DOMDocument::loadXML()
10+ * @uses \DOMDocument::saveXML()
11+ * @param string $string
12+ * @param bool $asDomDocument
13+ * @return \DOMDocument|string|null
14+ */
15+ public static function getFormatedXml ($ string , $ asDomDocument = false )
16+ {
17+ if (!empty ($ string ) && class_exists ('DOMDocument ' )) {
18+ $ dom = new \DOMDocument ('1.0 ' , 'UTF-8 ' );
19+ $ dom ->formatOutput = true ;
20+ $ dom ->preserveWhiteSpace = false ;
21+ $ dom ->resolveExternals = false ;
22+ $ dom ->substituteEntities = false ;
23+ $ dom ->validateOnParse = false ;
24+ try {
25+ if ($ dom ->loadXML ($ string )) {
26+ return $ asDomDocument ? $ dom : $ dom ->saveXML ();
27+ }
28+ } catch (\Exception $ exception ) {
29+ throw new \InvalidArgumentException (sprintf ('XML string is invalid ' ), null , $ exception );
30+ }
31+ }
32+ return $ asDomDocument ? null : $ string ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments