Thread View: nl.comp.programmeren
2 messages
2 total messages
Started by flor
Thu, 23 Oct 2008 15:27
xml in java
Author: flor
Date: Thu, 23 Oct 2008 15:27
Date: Thu, 23 Oct 2008 15:27
42 lines
2734 bytes
2734 bytes
Hallo,
Ik ben aan een java applicatie aan het knoeien en zit nu vast�.
Ik probeer een xml document te parsen door gebruik te maken van sax.
Ik heb al verschillende dingen kunnen inlezen door gebruik te maken van
volgende code:
> if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
>
> Element firstPersonElement = (Element)firstPersonNode;
>
> NodeList firstNameList = firstPersonElement.getElementsByTagName("FirstName");
> Element firstNameElement = (Element)firstNameList.item(0);
> NodeList textFNList = firstNameElement.getChildNodes();
> patient.firstName = ((Node)textFNList.item(0)).getNodeValue().trim();
> .......
Nu wil ik echter ook de lengte en het gewicht uitlezen:
> <Transaction>
> <Item>
> <ID Country="US" IDSystem="IdSys">11321</ID>
> <ItemType>
> <ID Country="US" IDSystem="Sys">70</ID>
> <Description Language="EN">Weight</Description>
> </ItemType>
> <ItemContent DataType="NM" Units="kg">75</ItemContent>
> </Item>
> <Item>
> <ID Country="US" IDSystem="IdSys">11321</ID>
> <ItemType>
> <ID Country="US" IDSystem="Sys">80</ID>
> <Description Language="EN">Height</Description>
> </ItemType>
> <ItemContent DataType="NM" Units="cm">180</ItemContent>
> </Item>
> </Transaction>
kan iemand me op weg helpen?
Gelieve ook in sax, zeker geen jdom want dat is veel te groot om mee op
te nemen in deze kleine, eenvoudige applicatie.
merci!
Re: xml in java
Author: Stefan Arentz
Date: Thu, 23 Oct 2008 16:43
Date: Thu, 23 Oct 2008 16:43
13 lines
1459 bytes
1459 bytes
flor <flor@nospam.invalid> writes: > Hallo, > > Ik ben aan een java applicatie aan het knoeien en zit nu vast�. Dit is geen SAX antwoord :-) Voor dat soort simpele XML gebruik ik altijd de 'Commons Digester'. In een paar regels code maak dan een parser die de xml kan vertalen naar classes die de data representeren. http://commons.apache.org/digester/ S.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads