Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
What is the best way to go about parsing XML in Java? I've been going about rewriting a project I have written, and it uses the org.w3c.dom.* classes to do so. This was mainly because I found information on it, but with all things Java it seems like there is a lot of outdated information out there. Basically, whats the best API for doing this, since any way I can simplify the code for this project would be extremely helpful.

Adbot
ADBOT LOVES YOU

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

zootm posted:

It entirely depends on what you want to do, and what your requirements are. Java has support for pretty much every method of parsing XML out there.

DOM allows you to traverse and manipulate an XML document as an object representing its structure.
SAX and StAX are stream parsers which scale well but essentially mean you have to maintain any state that you need yourself. StAX is a more modern "pull" parser which is a lot easier to use.
JAXB allows you to bind structured XML documents to and from corresponding basic "bean" objects automatically.
XPath allows you to query a loaded XML document for a given "path" allowing you to quickly query parts of the document.

Thanks for the information. This really helps me out, since I have been having difficulties locating the information I needed. It looks like I will be sticking with DOM, since my documents will never be excessively large and I am going to be parsing the XML generated from a program that makes a simple task extremely difficult due to it creating two separate nodes that contain slightly overlapping information by using reference IDs to identify the correlation.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

tef posted:

If you are just rewriting the output of a program from xml to xml, there are other options like xpath+xsl.

Although xsl is pretty useful it can be quite awkward being declarative.

I'm not sure, the way this works is fairly obtuse, such as
code:
<part1>
 <element id="123">
    <attribute></attribute>
    <link id="456" />
 </element>
 <links>
   <link idref="456" name="junk" />
 </links>
</part1>
<part2>
 <element idref="123">
   <samefuckingattributewithextrainfo>
      <whyisntthisabove />
   </samefuckingattributewithextrainfo>
 </element>
</part2>
obviously there can be more elements, but it's driving me nuts.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
I have a question that deals with Hibernate + Spring. I am working on a project that has two types of users. One is a parent, one is a child. A parent can register and create a new account and log in. Then, a parent can also create child users, which it has control to add and delete. These users can then log in.

How can I safely protect the user accounts from the client but still allow for this relationship in the ORM? The main issue is that I'd be serializing this collection to the client, which would then expose all these Account classes.

EDIT: I guess I should have clarified this, but my biggest concern is returning the password field to the client, which I would like to avoid doing.

CRIP EATIN BREAD fucked around with this message at 22:39 on Feb 15, 2010

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Mill Town posted:

Use a one-way hash on the passwords?

Edit: You should always hash your passwords. never store them in cleartext anywhere.

I'm currently hashing with a salted MD5, but I still would prefer to not even send that back to the user.

However, I think I figured out what I needed to do, it turns out that my externalizer/serializer has an ability to ignore fields in an entity bean, so I am ignoring the password field and setting and creating a separate service call for updating the password.

Adbot
ADBOT LOVES YOU

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

TRex EaterofCars posted:

Can't you just mark the field transient (or @Transient) and it won't be sent with the bean data?

This will cause it to not be persisted into the database. But as I mentioned above, I had to do it through the externalizer that was serializing the data over an AMF channel.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply