NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Simple XML parser

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
fluturel



Joined: 13 Jul 2010
Posts: 13

PostPosted: Wed Jul 14, 2010 11:04 pm    Post subject: Simple XML parser Reply with quote

I have an XML file just like the following:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
  <Employee type="permanent">
        <Name>Seagull</Name>
        <Id>3674</Id>
        <Age>34</Age>
   </Employee>
  <Employee type="contract">
        <Name>Robin</Name>
        <Id>3675</Id>
        <Age>25</Age>
    </Employee>
  <Employee type="permanent">
        <Name>Crow</Name>
        <Id>3676</Id>
        <Age>28</Age>
    </Employee>
</Personnel>

So nothing too complex. Just the basics. What's the easiest way of parsing this kind of XMLs ? Something like this would be nice:
Code:
String xmlAsAString;
XML xml = XML.parse(xmlAsAString);
System.out.println(xml.Employee[0].name);


Being so many parsers i really don't know which one to use Confused
Back to top
proximityinfotech6



Joined: 13 Jul 2010
Posts: 2

PostPosted: Thu Jul 15, 2010 5:03 am    Post subject: Reply with quote

This is where it gets complicated - because I'm on a client's server and he's running nginx (essentially apache rewritten by some crazy Russian to be lean so I'm told) which I've never used before. So - I don't know exactly if these packages are needed here as a result of the upgrade to 2.4? It seems unlikely as this would be detailed in the upgrade docs. SS 2.3.6 runs beautifully on this server, s
I'm all sorts of confused, but leaning toward nginx not being the issue here.
____________________________________________________________
Office Chairs | Chairs
Back to top
Shagil t
Posted via mailing list.





PostPosted: Fri Jul 16, 2010 6:07 pm    Post subject: Re: Simple XML parser Reply with quote

I think JAXB will be a good choice.
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/

On Thu, Jul 15, 2010 at 4:35 AM, fluturel <address-removed ([email]address-removed[/email])> wrote:
Quote:
I have an XML file just like the following:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
Back to top
nestor gomez munoz
Posted via mailing list.





PostPosted: Fri Jul 16, 2010 7:35 pm    Post subject: Re: Simple XML parser Reply with quote

If JAXB is not a choise, you can use the java XPahtAPI , and program
something like

String xpathExpression = "/Personnel/Employee";
Node nodes = (Node) xpath.evaluate(xpathExpression,

inputSource, XPathConstants.NODE);
for (int j = 0; j < nodes.getLength(); j++) {
xpathExpression = "./@type";
eType = (String) xpath.evaluate(xpathExpression,
nodes.item(j),
XPathConstants.STRING);
eName = xpath.evaluate("./Name", nodes.item(j),
XPathConstants.STRING);
eId = xpath.evaluate("./Id",nodes.item(j),
XPathConstants.INTEGER);
eAge = xpath.evaluate("./Age",nodes.item(j),
XPathConstants.INTEGER);
}


El vie, 16-07-2010 a las 23:12 +0530, Shagil t escribió:
Quote:
I think JAXB will be a good choice.
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/

On Thu, Jul 15, 2010 at 4:35 AM, fluturel <address-removed> wrote:
I have an XML file just like the following:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
<Employee type="permanent">
<Name>Seagull</Name>
<Id>3674</Id>
<Age>34</Age>
</Employee>
<Employee type="contract">
<Name>Robin</Name>
<Id>3675</Id>
<Age>25</Age>
</Employee>
<Employee type="permanent">
<Name>Crow</Name>
<Id>3676</Id>
<Age>28</Age>
</Employee>
</Personnel>



So nothing too complex. Just the basics. What's the easiest
way of parsing this kind of XMLs ? Something like this would
be nice:

Code:
String xmlAsAString;
XML xml = XML.parse(xmlAsAString);
System.out.println(xml.Employee[0].name);



Being so many parsers i really don't know which one to use :?




Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo