Skip to content

API_xar_subdoc_copyin

Rob Braun edited this page Jan 28, 2007 · 1 revision

Table of Contents

API Documentation

int32_t xar_subdoc_copyin(xar_subdoc_t s, unsigned char *buf, unsigned int size)

Unserialize an in-memory buffer to a xar_subdoc_t

Description

Unserializes an xml document contained in memory pointed to by buf. The subdocument structure, s, should have been allocated and initialized by a call to xar_subdoc_new(). On return, the subdocument s is populated from the xml document pointed to by buf (the length of buf described by the size parameter). On success, 0 is returned. On failure, -1 is returned.

Example

#include <xar/xar.h>

int main(int argc, char *argv[]) {
	xar_t x;
	xar_subdoc_t s;
	unsigned char *foo = "<foo><bar>baz</bar></foo>";
	unsigned int len = strlen(foo);

	x = xar_open(argv[1], WRITE);
	if( x == NULL ) {
		fprintf(stderr, "Error opening xarchive: %s\n", argv[1]);
		exit(1);
	}

	s = xar_subdoc_new(x);
	if( !s ) {
		fprintf(stderr, "Error creating new subdocument\n");
		exit(2);
	}

	if( xar_subdoc_copyin(s, buf, len) == -1  ) {
		fprinntf(stderr, "Error unserializing subdocument\n");
		exit(3);
	}

	...

	xar_close(x);
	
	...

}