Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
normalizeDocument example
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
)
;
return
[
]
;
}
private
static
function
shouldEnableEntityLoader
(
)
: bool
{
static
$dom
,
$schema
;
if
(
null ===
$dom
)
{
$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.'
)
;
}
}
if
(
null !==
$schemaOrCallable
)
{
$internalErrors
=
libxml_use_internal_errors
(
true
)
;