XML Development

Moderators: None (Apply to moderate this forum)
Number of threads: 252
Number of posts: 451

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I hardly doubt any1 will understand Posted by Gregry2 on 10 Jul 2005 at 4:32 PM
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
Report
Re: I hardly doubt any1 will understand Posted by infidel on 11 Jul 2005 at 8:25 AM
: 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


Report
Someone does! Posted by Gregry2 on 14 Jul 2005 at 7:15 PM
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 The C Programming Language
Report
Re: Someone does! Posted by infidel on 15 Jul 2005 at 7:01 AM
: 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.


infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.