: Its about an algorithm to parse, well, actualy store parsed data gained from an xml file. This is about programming, not web services and stuff, but i hope one here knows this. My freinds at C/C++ board dont seem to see it as related due to its title...So tither.
:
: Is this a good way, or a good model, or algorithm, or something for storing the information tagged in a xml file?
:
: We have a struct: (this is in C)
:
: struct node{
: char *name;
: void *information[];//or **
: attributes *atribs;//an array of structs explained later
: struct node *next;
: }
:
: for every tag we find we find we allocate a node,assign its name to the node.name (im not sure what its called, the text between '<' and '>'), and the void pointer array, well heres some explaining...
:
: first the text between the tags will be put in a string which pointer of that string will be an element of the array. If all the tagged area contains is text, then this will be the only member of the array.
:
: However, if a nother tag is encountered, it allocates another node, actually pushes it onto the stack (u can tell by the *next)and it repeats the process for that new node. The address of the new node becomes an element for the info array of in the last.
:
: Any text after the nested area becomes a second string.Im not sure if this is all great, but it keeps things in order.
:
: Therefore, all nodes can be nested. Any empty tags have NULL as a value for *info[] (or **info).
:
: This seems prettry good...may be...namespaces can probably have some seperation from name...
:
: Heres for the atrributes..
:
: typedef struct{
: char *name;
: char *value;
: }atrributes;
:
: for every single attrib we'll have one of these, storing its name and value accordingly.
:
: Thus, is this ok?
:
: Plz tell
I think the biggest problem is that your struct is essentially a linked-list node, where XML documents are trees. I.e. you shouldn't have a pointer to the "next" node, but rather an array of "children" nodes. And note that plain text is a kind of node as well, one with no attributes or children. It's been ages since I did C, so this is just a guess as to how I might approach a struct:
enum node_type {DOCUMENT, ELEMENT, ATTRIBUTE, TEXT, COMMENT};
struct node{
char *uri; // the namespace URI for the node
char *name; // the name of the node
node_type type; // what kind of node
struct node *attrs[]; // the node's attributes
struct node *children[]; // the node's children
}
Maybe that will give you a good place to start. I don't believe you need a separate type for attributes since they are just another kind of node with a name (and possibly a namespace URI) and a value (text node child).
My recommendation, though, is to use something like expat or lxml instead of rolling your own parser.
infidel
$ select * from users where clue > 0
no rows returned