181 lines · 4.5 KB · Text
RawDownload
.TH XML 2.SH NAMExmlattr,xmlcalloc,xmlelem,xmlfind,xmlfree,xmllook,xmlmalloc,xmlnew,xmlparse,xmlprint,xmlstrdup,xmlvalue\- XML parser.SH SYNOPSIS.de PB.PP.ft L.nf...PB#include <u.h>#include <libc.h>#include <xml.h>.PBenum {	Fcrushwhite = 1,	Fstripnamespace = 2,};.PBstruct Xml{	Elem *root;		/* root of tree */	char *doctype;		/* DOCTYPE structured comment, or nil */	...};.PBstruct Elem {	Elem *next;		/* next element at this hierarchy level */	Elem *child;		/* first child of this node */	Elem *parent;		/* parent of this node */	Attr *attrs;		/* linked list of atributes */	char *name;		/* element name */	char *pcdata;		/* pcdata following this element */	int line;			/* Line number (for errors) */};.PBstruct Attr {	Attr *next;		/* next atribute */	Elem *parent;		/* parent element */	char *name;		/* atributes name */	char *value;		/* atributes value */};.PB.PD 0.ta +\w'\fL      'u +\w'\fL    'u +6n +4nAttr*	xmlattr(Xml *xp, Attr **root, Elem *parent,		char *name, char *value).PBElem*	xmlelem(Xml *xp, Elem **root, Elem *parent, char *name).PBElem*	xmlfind(Xml *xp, Elem *ep, char *path).PBElem*	xmllook(Elem *ep, char *path, char *attr, char *value).PBXml*	xmlnew(int blksize).PBXml*	xmlparse(int fd, int blksize, int flags).PBchar*	xmlvalue(Elem *ep, char *name).PBvoid*	xmlmalloc(Xml *xp, usize size).PBvoid*	xmlcalloc(Xml *xp, usize nelem, usize elemsz).BPvoid*	xmlstrdup(Xml *xp, char *s).PBvoid	xmlfree(Xml *xp).PBvoid	xmlprint(Xml *xp, int fd).SH DESCRIPTION.PP.I Libxmlis a library for manipulating an XML document, in-memory (known as the DOM model). Each element may have anumber of children, each of which has a number of attributes, each attributehas a single value. All elements contain a pointer to their parentelement, the root element having a nil parent pointer..I Pcdata(free form text) found between elements is attached to element which follows it.The line numbers where each element was found is stored to allow unambigiouserror messages during later analysis..PPStrings are stored in two data structures: a binary tree for common names such aselement and attribute names. Uncommon names such as values andpcdata are stored in a simple, unmanaged heap. These steps vastly reduce the memoryfootprint of the parsed file and the time needed to free the XML data..PP.I Xmlparsereads the given file and builds an in-memory tree..I Blocksizecontrols the granularity of allocation of the string heap described above,8192 is typically used.The.I flagsfield allows some control over the parser, it is a bitwise.B orof the following values: .TP 10.B FcrushwhiteAll strings whitespace in PCdata is replaced by a single space and leading and trailing whitespace isremoved..TP.B FstripsnamespaceRemove leading namespace strings form all element and attribute names; this effectively ignores namespaceswhich can lead to parsing ambiguities, though in practice it has not been a problem—yet..PPXml trees may also be built up by calling.I xmlnewto create the XML tree, followed by.I xmlelemand.I xmlattrto create individual elements and attributes  respectively..I Xmlelemtakes the address of the root of an element list to which the newelement should be appended, the address of the parent node the newelement should reference, and the nameof the node to create; It returns the address of the created element..PP.I Xmlattrattaches an attribute to an existing element. It takes a list pointerand parent pointer like .IR xmlelem ,but requires both an atribute name and value,and returns the address of the new attribute..PP.I Xmllookdescends through the tree rooted at.I epusing the path specified in.IR path .It then returns if.I elemis nil, or continues to search for a matching element.if.I attrand .I valueare not nil, the search will continue forfor an element which contains this attribute and value pair..PP.I Xmlvaluesearches the given element's attribute list and returns thevalue of the attribute found or nil if that attribute is not found. .PP.I Xmlprintwrites the XML hierarchy rooted at \fIep\fR as text to the givenfile descriptor..PP.IR Xmlmalloc ,.IR xmlcalloc ,and.IR xmlstrdupallocate memory within the.B Xmltree..I Xmlfreefrees all memory used by the given.B Xmltree..SH SOURCE/sys/src/libxml.SH "SEE ALSO".IR xb (1)..SH BUGSNamespaces should be handled properly..PPA SAX model parser will probably be needed sometime (e.g. for Ebooks)..PPUTF-16 headers should be respected but UTF-16 files seems rare.