6

I'm working to create a library for my app in C. I want to parse a XML file in my code. So, how can i do it in C ?

I know its java implementation but how can i parse a XML in my C code ?

What are the libraries that can be used for the purpose ?

Neji
  • 6,591
  • 5
  • 43
  • 66

3 Answers3

3

I suggest Expat, I've used with many projects and it is very simple to use and has extremely small overhead. Its code base is also quite stable.

Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document (like start tags).

However with every other external project mentioned, you need to build it yourself.

auselen
  • 27,577
  • 7
  • 73
  • 114
  • you have helped me with a answer in past, can you help me with this question : http://stackoverflow.com/questions/13802869/working-with-aosp – Neji Dec 11 '12 at 06:50
  • can we talk in chat room if you are free! – Neji Dec 11 '12 at 07:25
  • Hi, today there are an native-XML-Lib? is it LibXML2 as we [seem something here](https://android.googlesource.com/platform/external/libxml2.git)? And about Java-implementations for modern XQuery and XPath2, is so heavy for Android? – Peter Krauss Nov 05 '17 at 22:30
2

you should use c library for parsing xmls. here are some famous library links.. you can check

http://www.jclark.com/xml/expat.html

http://www.xmlsoft.org/

http://tibleiz.net/asm-xml/benchmark.html

you can find many other library to parse xml. But if you have any lightweight parsing task then you can use

http://www.minixml.org/

stinepike
  • 54,068
  • 14
  • 92
  • 112
  • 1
    To add to the answer, build one of the listed libraries and use them. There is no inbuilt library in the native section of the android base system (or any other POSIX based OS). – Samveen Dec 10 '12 at 07:23
  • Today, 2017, there are a "nateve XML lib"? Seems XMLSOFT.ORG, the maintainer of LibXML2, as I see (perhaps random) at https://android.googlesource.com/platform/external/libxml2.git – Peter Krauss Nov 05 '17 at 22:25
2

I have used http://www.minixml.org/ so i suggest to use this. Minixml is quite simple and easy to understand and use.

So you can download whole code of minixml and cross compile it for Android using Android toolchain or android NDK. And now Link that library to your jni code and use its API in your c code.

Just refference for includeing 3rd party library in jni code see

How to link any library in ndk application

Community
  • 1
  • 1
Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222