Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xml_field
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
xml_field
Commits
bdd738b5
Commit
bdd738b5
authored
Jul 31, 2012
by
Aaron Klump
Browse files
Options
Downloads
Patches
Plain Diff
made _xml_field_parse_xml_string a private function; publicly use xml_field_xml instead;
more documentation
parent
2023ad6b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.txt
+9
-5
9 additions, 5 deletions
README.txt
xml_field.module
+40
-32
40 additions, 32 deletions
xml_field.module
with
49 additions
and
37 deletions
README.txt
+
9
−
5
View file @
bdd738b5
...
...
@@ -94,13 +94,17 @@ $description = xml_field($node, 'description', NULL, array('check_markup', $form
Study the docblocks in the code for more info.
API:
* xml_field_xml()
* xml_field()
* xml_field_format()
API
The three main API Functions:
* xml_field_xml(): to obtain an XML object
* xml_field(): to access XML values
* xml_field_format(): to obtain a string version of any XML
* xml_field_output(): to output XML to the browser
Additional API functions:
* xml_field_is_valid_xml_string()
* xml_field_parse_xml_string()
* xml_field_xml_fields()
* theme_xml()
OTHER EXAMPLE CODE:
...
...
This diff is collapsed.
Click to expand it.
xml_field.module
+
40
−
32
View file @
bdd738b5
...
...
@@ -3,6 +3,13 @@
* @file
* Defines the xml field type
*
* Comparison of API Functions:
*
* When you want a string back use: xml_field_format()
* When you want a simpleXMLElement object back: use xml_field_xml()
* When you want a node value from XML use: xml_field()
* When you want to output to browser use: xml_field_output()
*
* @ingroup xml_field XML Field
* @{
*/
...
...
@@ -16,7 +23,7 @@
define
(
'XML_FIELD_PRESERVE_WHITESPACE'
,
TRUE
);
/**
* Returns the xml from: entities, fields, objects, strings
* Returns the xml
object
from: entities, fields, objects, strings
*
* All of the following are valid input sources and will yield the same result,
it is your preference how you'd like to use this powerful function (take into
...
...
@@ -55,8 +62,8 @@ function xml_field_xml($input, $callback_multiple = 'array_shift') {
}
// String
if
(
is_string
(
$input
)
&&
xml_field_
is_valid
_xml_string
(
$input
))
{
return
simplexml_load_string
(
$input
)
;
if
(
$xml
=
_
xml_field_
parse
_xml_string
(
$input
))
{
return
$xml
;
}
$fields
=
xml_field_xml_fields
();
...
...
@@ -168,7 +175,7 @@ function xml_field($xml, $selector = NULL, $attribute = NULL, $default = '', $ca
}
/**
*
Add proper
formatt
ing/
sanitiz
ation to XML
*
Returns
formatt
ed or
sanitiz
ed XML string
*
* @param mixed $xml
* Anythign allowed by xml_field_xml()
...
...
@@ -270,6 +277,33 @@ function xml_field_format($xml, $htmlentities = TRUE, $options = array()) {
return
trim
(
$result
);
}
/**
* Returns data in XML format.
*
* Use this when serving XML as it sets the header for XML output.
*
* @param $var
* (optional) If set, the variable will be run through xml_field_format and
then output.
@see xml_field_format()
*/
function
xml_field_output
(
$var
=
NULL
,
$options
=
array
())
{
// We are returning XML, so tell the browser.
drupal_add_http_header
(
'Content-Type'
,
'text/xml'
);
if
(
!
variable_get
(
'xml_field_preserve_whitespace'
,
XML_FIELD_PRESERVE_WHITESPACE
))
{
$options
+=
array
(
'tab'
=>
''
,
'break'
=>
''
,
);
}
if
(
isset
(
$var
))
{
echo
xml_field_format
(
$var
,
FALSE
,
$options
);
}
}
/**
* Parse an xml string and return the simpleXMLElement object
*
...
...
@@ -302,7 +336,7 @@ function xml_field_format($xml, $htmlentities = TRUE, $options = array()) {
*
* @see http://php.net/manual/en/class.simplexmlelement.php
*/
function
xml_field_parse_xml_string
(
$xml
)
{
function
_
xml_field_parse_xml_string
(
$xml
)
{
$parsed
=
is_string
(
$xml
)
?
@
simplexml_load_string
(
$xml
)
:
FALSE
;
return
$parsed
instanceof
SimpleXMLElement
?
$parsed
:
FALSE
;
}
...
...
@@ -315,7 +349,7 @@ function xml_field_parse_xml_string($xml) {
* @return bool
*/
function
xml_field_is_valid_xml_string
(
$xml
)
{
return
xml_field_parse_xml_string
(
$xml
)
===
FALSE
?
FALSE
:
TRUE
;
return
_
xml_field_parse_xml_string
(
$xml
)
===
FALSE
?
FALSE
:
TRUE
;
}
/**
...
...
@@ -358,32 +392,6 @@ function xml_field_xml_fields($include_bundles_and_entity_types = FALSE) {
return
$include_bundles_and_entity_types
?
$entities
:
$field_list
;
}
/**
* Returns data in XML format.
*
* Use this when serving XML as it sets the header for XML output.
*
* @param $var
* (optional) If set, the variable will be run through xml_field_format and
then output.
@see xml_field_format()
*/
function
xml_field_output
(
$var
=
NULL
,
$options
=
array
())
{
// We are returning XML, so tell the browser.
drupal_add_http_header
(
'Content-Type'
,
'text/xml'
);
if
(
!
variable_get
(
'xml_field_preserve_whitespace'
,
XML_FIELD_PRESERVE_WHITESPACE
))
{
$options
+=
array
(
'tab'
=>
''
,
'break'
=>
''
,
);
}
if
(
isset
(
$var
))
{
echo
xml_field_format
(
$var
,
FALSE
,
$options
);
}
}
/**
* Implements hook_field_info().
...
...
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