Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
graphicsframework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
einsteinathome
graphicsframework
Commits
1c241859
Commit
1c241859
authored
16 years ago
by
Oliver Bock
Browse files
Options
Downloads
Patches
Plain Diff
General improvement
* Better error/exception handling * Better memory management * Minor bug fix
parent
cd242921
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/framework/Libxml2Adapter.cpp
+49
-10
49 additions, 10 deletions
src/framework/Libxml2Adapter.cpp
with
49 additions
and
10 deletions
src/framework/Libxml2Adapter.cpp
+
49
−
10
View file @
1c241859
...
...
@@ -52,35 +52,74 @@ string Libxml2Adapter::getSingleNodeContentByXPath(const string xpath)
// no document available!
if
(
!
m_xmlDocument
)
return
(
""
);
// prepare xpath search
stringstream
buffer
;
string
result
=
""
;
// prepare xpath context
xmlXPathContextPtr
xpathCtx
=
xmlXPathNewContext
(
m_xmlDocument
);
if
(
xpathCtx
==
NULL
)
{
cerr
<<
"Error getting XPath context!"
<<
endl
;
return
(
""
);
}
// prepare xpath expression
xmlChar
*
xpathExpr
=
xmlCharStrdup
(
xpath
.
c_str
());
if
(
xpathExpr
==
NULL
)
{
cerr
<<
"Error preparing XPath expression: "
<<
xpath
<<
endl
;
xmlXPathFreeContext
(
xpathCtx
);
return
(
""
);
}
// run xpath query
xmlXPathObjectPtr
xpathObj
=
xmlXPathEvalExpression
(
xpathExpr
,
xpathCtx
);
if
(
xpathObj
==
NULL
)
{
cerr
<<
"Error evaluating XPath expression: "
<<
xpath
<<
endl
;
xmlFree
(
xpathExpr
);
xmlXPathFreeContext
(
xpathCtx
);
return
(
""
);
}
// retrieve node set returned by xpath query
xmlNodeSetPtr
nodes
=
xpathObj
->
nodesetval
;
// how many nodes did we find?
int
size
=
(
nodes
)
?
nodes
->
nodeNr
:
0
;
if
(
size
=
=
0
)
{
if
(
size
<
=
0
)
{
cerr
<<
"No node found using XPath expression: "
<<
xpath
<<
endl
;
re
turn
(
""
)
;
re
sult
=
""
;
}
else
if
(
size
<
1
)
{
else
if
(
size
>
1
)
{
cerr
<<
"More than node found using XPath expression: "
<<
xpath
<<
endl
;
re
turn
(
""
)
;
re
sult
=
""
;
}
else
{
// prepare conversion stream
ostringstream
converter
;
converter
.
exceptions
(
ios_base
::
badbit
|
ios_base
::
failbit
);
// get xml content
xmlChar
*
nodeContent
=
xmlNodeListGetString
(
m_xmlDocument
,
nodes
->
nodeTab
[
0
]
->
xmlChildrenNode
,
1
);
try
{
// convert xml contents
buffer
<<
xmlNodeListGetString
(
m_xmlDocument
,
nodes
->
nodeTab
[
0
]
->
xmlChildrenNode
,
1
);
converter
<<
nodeContent
;
result
=
converter
.
str
();
}
catch
(
ios_base
::
failure
)
{
cerr
<<
"Error converting XPath node content!"
<<
endl
;
result
=
""
;
}
// clean up
xmlFree
(
nodeContent
);
}
// clean up
xmlFree
(
xpathExpr
);
xmlXPathFreeObject
(
xpathObj
);
xmlXPathFreeContext
(
xpathCtx
);
return
(
buffer
.
str
()
);
return
(
result
);
}
string
Libxml2Adapter
::
getSingleNodeContentByXPath
(
const
string
xml
,
const
string
url
,
const
string
xpath
)
...
...
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