16

How would you convert / cast an xmlChar* to char* from the libxml2 library? Thanks.

mobilekid
  • 1,629
  • 5
  • 19
  • 27

2 Answers2

13

If you take a look at the examples, for instance io2.c, you'll notice that they just blithely cast it to a char *:

printf("%s", (char *) xmlbuff);
darelf
  • 4,589
  • 2
  • 16
  • 11
6

Looks like it's just unsigned char. So it should be safe to cast as long as you're not doing arithmetic on it.

But, you probably don't need to as that page has the key string functionality implemented in terms of the type.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • *For now*, it's unsigned char - but why make a simple alias for char if they don't expect the typedef to change in the future? – Mihai Jun 17 '16 at 11:46