Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I hardly doubt any1 will understand

Gregry2Gregry2 Posts: 607Member
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

{2}rIng

Comments

  • infidelinfidel Posts: 2,900Member
    : 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:

    [code]
    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
    }
    [/code]

    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.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Gregry2Gregry2 Posts: 607Member
    Thanx, this is a good model.

    Actually, i was going to write a XML based database in C. I actually need to brush up cause im really a begginer in XML as well.

    You probably left C hoping not to return, sorry to bring you back bad memories!

    Thank you again.

    {2}rIng

    "FIRST make it run, THEN make it run faster."
    --Brian Kernighan, Co-Author of [italic]The C Programming Language[/italic]
  • infidelinfidel Posts: 2,900Member
    : Thanx, this is a good model.

    Well, it's probably OK, but it was just off the top of my head so no guarantees.

    : Actually, i was going to write a XML based database in C. I actually need to brush up cause im really a begginer in XML as well.

    Good luck

    : You probably left C hoping not to return, sorry to bring you back bad memories!

    Actually, C can be fun. I've used a tiny bit of it lately because we needed a Java program to get a certain registry value, but Java's runtime is sandboxed to a particular key in the registry. I had to do a little JNI to call the win32 API so I could read our keys.

    I try to do all of my pet projects in Python, though.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.