Best way to populate an object from XML
Say I have an employee class. It is just created and needs to populate it's
attribute (i.e. name, id, position), so the class retrieves it's information
from the database in XML format i.e.
<Employee>
<Name>Me</Name>
<ID>10</ID>
<Position>Programmer</Position>
</Employee>
What is the best/most efficient way to extract the attribute information
from the XML? Implement SAX? Make a DOM and parse? Xpath?
James
# 1 Re: Best way to populate an object from XML
If you are using Java check out Castor (www.exolabs.com) and Glue (www.themindelectric.com).
"James Smith" <a@b.c> wrote:
>
>Say I have an employee class. It is just created and needs to populate
it's
>attribute (i.e. name, id, position), so the class retrieves it's information
>from the database in XML format i.e.
><Employee>
> <Name>Me</Name>
> <ID>10</ID>
> <Position>Programmer</Position>
></Employee>
>
>What is the best/most efficient way to extract the attribute information
>from the XML? Implement SAX? Make a DOM and parse? Xpath?
>
>James
>
MarkN at 2007-11-11 23:30:09 >

# 2 Re: Best way to populate an object from XML
"MarkN" <enterprise.@127.0.0.1> wrote:
>
>If you are using Java check out Castor (www.exolabs.com) and Glue (www.themindelectric.com).
I am currently using VB6. The exolabs.com link didn't work. The Glue is
interesting however it is a java product. I'd be interested in reading Java
articles if you know of any since most Java concepts can be translated back
to VB.
James at 2007-11-11 23:31:09 >

# 3 Re: Best way to populate an object from XML
>
>I am currently using VB6. The exolabs.com link didn't work.
Sorry http://www.exolab.org/.
> The Glue is
>interesting however it is a java product.
And is why I said, "if you are using Java"
>I'd be interested in reading Java
>articles if you know of any
Check out Javaworld, JavaSkyline, IBM's Java site, Java Developers Journal,
...
> ...since most Java concepts can be translated back to VB.
Some can but these can't (and a lot of others can't either - if they can
why is the conversion of VB projects to VB.Net so full of "Need to fix"?).
These can't because they use reflection. You will need to go to MS.Net
if you want to use these techniques.
With Java and MS.Net (VB.Net or C#) you can create objects from the database
without writing XML or SQL. With Java, I am using a tool called Hibernate
(an open source tool) without writing any SQL or without an RDBMS to XML
to Object conversion. I would compare it to MS.Net's DataSets but I don't
want to cloud the issue.
Mark
MarkN at 2007-11-11 23:32:13 >

# 4 Re: Best way to populate an object from XML
"James" <enterprise.@127.0.0.1> wrote:
>
>"MarkN" <enterprise.@127.0.0.1> wrote:
>>
>>If you are using Java check out Castor (www.exolabs.com) and Glue (www.themindelectric.com).
>
>I am currently using VB6. The exolabs.com link didn't work. The Glue is
>interesting however it is a java product. I'd be interested in reading Java
>articles if you know of any since most Java concepts can be translated back
>to VB.
if you are using VB6, DOM will be your no brain choice.
Phil at 2007-11-11 23:33:12 >

# 5 Re: Best way to populate an object from XML
XML Serialization might work here. (refer .NET)
"Phil" <yzhang@pcsigroup.com> wrote:
>
>"James" <enterprise.@127.0.0.1> wrote:
>>
>>"MarkN" <enterprise.@127.0.0.1> wrote:
>>>
>>>If you are using Java check out Castor (www.exolabs.com) and Glue (www.themindelectric.com).
>>
>>I am currently using VB6. The exolabs.com link didn't work. The Glue is
>>interesting however it is a java product. I'd be interested in reading
Java
>>articles if you know of any since most Java concepts can be translated
back
>>to VB.
>
>if you are using VB6, DOM will be your no brain choice.
at 2007-11-11 23:34:11 >

# 6 Re: Best way to populate an object from XML
Take a look at this article from VB Programmer's Journal.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbpj01/html/pc0107.asp
I had to modify it a bit, but in general it works very well.
"James Smith" <a@b.c> wrote:
>
>Say I have an employee class. It is just created and needs to populate
it's
>attribute (i.e. name, id, position), so the class retrieves it's information
>from the database in XML format i.e.
><Employee>
> <Name>Me</Name>
> <ID>10</ID>
> <Position>Programmer</Position>
></Employee>
>
>What is the best/most efficient way to extract the attribute information
>from the XML? Implement SAX? Make a DOM and parse? Xpath?
>
>James
>
Darryl at 2007-11-11 23:35:16 >
