Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
enonce
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
programmation_sequentielle
travaux_pratiques
c_lang
shortest_path
enonce
Commits
c13fdc46
Commit
c13fdc46
authored
5 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
updated files
parent
8c472f1c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.c
+16
-0
16 additions, 0 deletions
main.c
xml_parser.c
+44
-0
44 additions, 0 deletions
xml_parser.c
xml_parser.h
+2
-0
2 additions, 0 deletions
xml_parser.h
with
62 additions
and
0 deletions
main.c
0 → 100644
+
16
−
0
View file @
c13fdc46
#include
<stdio.h>
#include
<string.h>
#include
<libxml/parser.h>
#include
<libxml/tree.h>
#include
"xml_parser.h"
int
main
()
{
char
filename
[]
=
"villes.xml"
;
read_xml
(
filename
);
return
EXIT_SUCCESS
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
xml_parser.c
+
44
−
0
View file @
c13fdc46
...
@@ -44,3 +44,47 @@ void graph_xml_parser(xmlNode * a_node)
...
@@ -44,3 +44,47 @@ void graph_xml_parser(xmlNode * a_node)
}
}
}
}
int
read_xml
(
const
char
*
filename
)
{
// Init libxml
xmlInitParser
();
LIBXML_TEST_VERSION
// create a parser context
xmlParserCtxtPtr
ctxt
;
xmlDocPtr
doc
=
NULL
;
ctxt
=
xmlNewParserCtxt
();
if
(
ctxt
==
NULL
)
{
fprintf
(
stderr
,
"Failed to allocate parser context
\n
"
);
return
EXIT_FAILURE
;
}
// parse the file, without error validation
doc
=
xmlCtxtReadFile
(
ctxt
,
filename
,
NULL
,
XML_PARSE_NOERROR
);
// check if parsing suceeded
if
(
doc
==
NULL
)
{
fprintf
(
stderr
,
"Failed to parse %s
\n
"
,
filename
);
}
else
{
/* check if validation suceeded */
if
(
ctxt
->
valid
==
0
)
fprintf
(
stderr
,
"Failed to validate %s
\n
"
,
filename
);
}
xmlNode
*
root_element
=
xmlDocGetRootElement
(
doc
);
// get cities from xml
city_xml_parser
(
root_element
);
// get graph from xml
graph_xml_parser
(
root_element
);
// free the document
xmlFreeDoc
(
doc
);
// free up the parser context
xmlFreeParserCtxt
(
ctxt
);
return
EXIT_SUCCESS
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
xml_parser.h
+
2
−
0
View file @
c13fdc46
...
@@ -24,4 +24,6 @@ void ville_xml_parser(xmlNode * a_node);
...
@@ -24,4 +24,6 @@ void ville_xml_parser(xmlNode * a_node);
*/
*/
void
graph_xml_parser
(
xmlNode
*
a_node
);
void
graph_xml_parser
(
xmlNode
*
a_node
);
int
read_xml
(
const
char
*
filename
);
#endif
#endif
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