Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getXmlErrors example
public
static
function
validateSchema
(
\DOMDocument
$dom
)
: array
{
$xliffVersion
=
static
::
getVersionNumber
(
$dom
)
;
$internalErrors
=
libxml_use_internal_errors
(
true
)
;
if
(
$shouldEnable
= self::
shouldEnableEntityLoader
(
)
)
{
$disableEntities
=
libxml_disable_entity_loader
(
false
)
;
}
try
{
$isValid
= @
$dom
->
schemaValidateSource
(
self::
getSchema
(
$xliffVersion
)
)
;
if
(
!
$isValid
)
{
return
self::
getXmlErrors
(
$internalErrors
)
;
}
}
finally
{
if
(
$shouldEnable
)
{
libxml_disable_entity_loader
(
$disableEntities
)
;
}
}
$dom
->
normalizeDocument
(
)
;
libxml_clear_errors
(
)
;
libxml_use_internal_errors
(
$internalErrors
)
;
if
(
!\
extension_loaded
(
'dom'
)
)
{
throw
new
\
LogicException
(
'Extension DOM is required.'
)
;
}
$internalErrors
=
libxml_use_internal_errors
(
true
)
;
libxml_clear_errors
(
)
;
$dom
=
new
\
DOMDocument
(
)
;
$dom
->validateOnParse = true;
if
(
!
$dom
->
loadXML
(
$content
, \LIBXML_NONET | \LIBXML_COMPACT
)
)
{
throw
new
XmlParsingException
(
implode
(
"\n",
static
::
getXmlErrors
(
$internalErrors
)
)
)
;
}
$dom
->
normalizeDocument
(
)
;
libxml_use_internal_errors
(
$internalErrors
)
;
foreach
(
$dom
->childNodes
as
$child
)
{
if
(
\XML_DOCUMENT_TYPE_NODE ===
$child
->nodeType
)
{
throw
new
XmlParsingException
(
'Document types are not allowed.'
)
;
}
}