Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
c76426b5
Commit
c76426b5
authored
10 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Fix namespaces.
parent
44818e22
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Utils/XML.php
+24
-21
24 additions, 21 deletions
lib/SimpleSAML/Utils/XML.php
with
24 additions
and
21 deletions
lib/SimpleSAML/Utils/XML.php
+
24
−
21
View file @
c76426b5
...
...
@@ -14,18 +14,21 @@ class XML
/**
* Format a DOM element.
*
* This function takes in a DOM element, and inserts whitespace to make it more
*
readable. Note that whitespace
added previously will be removed.
* This function takes in a DOM element, and inserts whitespace to make it more
readable. Note that whitespace
* added previously will be removed.
*
* @param DOMElement $root The root element which should be formatted.
* @param string $indentBase The indentation this element should be assumed to
*
have. Default is an empty
string.
* @param
\
DOMElement $root The root element which should be formatted.
* @param string
$indentBase The indentation this element should be assumed to
have. Defaults to an empty
* string.
*
* @throws \SimpleSAML_Error_Exception If $root is not a DOMElement or $indentBase is not a string.
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
public
static
function
formatDOMElement
(
DOMElement
$root
,
$indentBase
=
''
)
public
static
function
formatDOMElement
(
\
DOMElement
$root
,
$indentBase
=
''
)
{
assert
(
is_string
(
$indentBase
));
if
(
!
is_string
(
$indentBase
))
{
throw
new
\SimpleSAML_Error_Exception
(
'Invalid input parameters'
);
}
// check what this element contains
$fullText
=
''
;
// all text in this element
...
...
@@ -34,10 +37,10 @@ class XML
for
(
$i
=
0
;
$i
<
$root
->
childNodes
->
length
;
$i
++
)
{
$child
=
$root
->
childNodes
->
item
(
$i
);
if
(
$child
instanceof
DOMText
)
{
if
(
$child
instanceof
\
DOMText
)
{
$textNodes
[]
=
$child
;
$fullText
.
=
$child
->
wholeText
;
}
elseif
(
$child
instanceof
DOMComment
||
$child
instanceof
DOMElement
)
{
}
elseif
(
$child
instanceof
\
DOMComment
||
$child
instanceof
\
DOMElement
)
{
$childNodes
[]
=
$child
;
}
else
{
// unknown node type. We don't know how to format this
...
...
@@ -47,7 +50,7 @@ class XML
$fullText
=
trim
(
$fullText
);
if
(
strlen
(
$fullText
)
>
0
)
{
// we contain text
// we contain text
elf
$hasText
=
true
;
}
else
{
$hasText
=
false
;
...
...
@@ -67,7 +70,7 @@ class XML
if
(
$hasText
)
{
// only text - add a single text node to the element with the full text
$root
->
appendChild
(
new
DOMText
(
$fullText
));
$root
->
appendChild
(
new
\
DOMText
(
$fullText
));
return
;
}
...
...
@@ -82,16 +85,16 @@ class XML
$childIndentation
=
$indentBase
.
' '
;
foreach
(
$childNodes
as
$node
)
{
// add indentation before node
$root
->
insertBefore
(
new
DOMText
(
"
\n
"
.
$childIndentation
),
$node
);
$root
->
insertBefore
(
new
\
DOMText
(
"
\n
"
.
$childIndentation
),
$node
);
// format child elements
if
(
$node
instanceof
DOMElement
)
{
if
(
$node
instanceof
\
DOMElement
)
{
self
::
formatDOMElement
(
$node
,
$childIndentation
);
}
}
// add indentation before closing tag
$root
->
appendChild
(
new
DOMText
(
"
\n
"
.
$indentBase
));
$root
->
appendChild
(
new
\
DOMText
(
"
\n
"
.
$indentBase
));
}
/**
...
...
@@ -104,19 +107,19 @@ class XML
* to ''.
*
* @return string The formatted string.
*
* @throws SimpleSAML_Error_Exception If the input does not parse correctly as an XML string.
*
* @throws \SimpleSAML_Error_Exception If the input does not parse correctly as an XML string or parameters are not
* strings.
* @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
*/
public
static
function
formatXMLString
(
$xml
,
$indentBase
=
''
)
{
assert
(
'is_string($xml)'
);
assert
(
'is_string($indentBase)'
);
if
(
!
is_string
(
$xml
)
||
!
is_string
(
$indentBase
))
{
throw
new
\SimpleSAML_Error_Exception
(
'Invalid input parameters'
);
}
$doc
=
new
DOMDocument
();
$doc
=
new
\
DOMDocument
();
if
(
!
$doc
->
loadXML
(
$xml
))
{
throw
new
SimpleSAML_Error_Exception
(
'Error parsing XML string.'
);
throw
new
\
SimpleSAML_Error_Exception
(
'Error parsing XML string.'
);
}
$root
=
$doc
->
firstChild
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment