001 package railo.runtime.functions.decision; 002 003 import java.io.StringReader; 004 005 import org.w3c.dom.Node; 006 import org.xml.sax.InputSource; 007 008 import railo.runtime.PageContext; 009 import railo.runtime.ext.function.Function; 010 import railo.runtime.op.Caster; 011 import railo.runtime.text.xml.XMLUtil; 012 013 /** 014 * Check if a String is a well-formed XML 015 */ 016 public final class IsXML implements Function { 017 018 public static boolean call(PageContext pc, Object xml) { 019 if(xml instanceof Node) return true; 020 021 try { 022 XMLUtil.parse(new InputSource(new StringReader(Caster.toString(xml))),null,false); 023 return true; 024 } 025 catch(Exception e) { 026 return false; 027 } 028 } 029 }