Fetching between two elements

View: New views
4 Messages — Rating Filter:   Alert me  

Fetching between two elements

by deneme.true :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I want to parse between two elements. For example:

<root>
<one>1</one>
<two>2</two>
<three>3</three>
<four>4</four>
<five>5</five>
</root>

How can I fetch from 2(<two>2</two>) through 4(<four>4</four>) tag?

Thanks in advance.
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

RE: Fetching between two elements

by Deepa Janamatti (RBIN/EMT2) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Document doc = new Document("<xml file path>");
Element root = doc.getRootElement();
//write logic to fetch the "four" tag
Element fourEle;
fourEle.getParent().getChild("two");

Regards,
Deepa

-----Original Message-----
From: jdom-interest-bounces@... [mailto:jdom-interest-bounces@...] On Behalf Of deneme.true@...
Sent: Wednesday, 2. April 2008 10:31 PM
To: jdom-interest@...
Subject: [jdom-interest] Fetching between two elements

Hi,

I want to parse between two elements. For example:

<root>
<one>1</one>
<two>2</two>
<three>3</three>
<four>4</four>
<five>5</five>
</root>

How can I fetch from 2(<two>2</two>) through 4(<four>4</four>) tag?

Thanks in advance.
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

RE: Fetching between two elements

by Deepa Janamatti (RBIN/EMT2) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 Sorry, change the below line to
Document doc = new SAXBuilder().build(new File("<xml file path>"));

-----Original Message-----
From: Deepa Janamatti (RBEI/EMT2)
Sent: Thursday, 3. April 2008 9:16 AM
To: 'deneme.true@...'; jdom-interest@...
Subject: RE: [jdom-interest] Fetching between two elements

Hi,

Document doc = new Document("<xml file path>");
Element root = doc.getRootElement();
//write logic to fetch the "four" tag
Element fourEle;
fourEle.getParent().getChild("two");

Regards,
Deepa

-----Original Message-----
From: jdom-interest-bounces@... [mailto:jdom-interest-bounces@...] On Behalf Of deneme.true@...
Sent: Wednesday, 2. April 2008 10:31 PM
To: jdom-interest@...
Subject: [jdom-interest] Fetching between two elements

Hi,

I want to parse between two elements. For example:

<root>
<one>1</one>
<two>2</two>
<three>3</three>
<four>4</four>
<five>5</five>
</root>

How can I fetch from 2(<two>2</two>) through 4(<four>4</four>) tag?

Thanks in advance.
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...

Re: Fetching between two elements

by deneme.true :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for response:

But my problem doesn't to fetch elements one by one. I want to fetch
this three elements 2,3,4 tags with a while or for loop. I try this
possibilities:

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("xmlfile.xml"));
Element endeks = doc.getRootElement();
Filter filter = new  ContentFilter(ContentFilter.ELEMENT);
List list = endeks.getContent(filter);

int start=list.indexOf("<two>");
int end = list.indexOf("<four>");
System.out.println(list.toString());
System.out.println(start+"|"+end);

start and end integers don't give any result and list.toString() method
output is:

[[Element: <one/>], [Element: <two/>], [Element: <three/>], [Element:
<four/>], [Element: <five/>]]

when I try this code for indexOf method signature.

int start=list.indexOf("<two/>");
int end = list.indexOf("<four/>");

It doesn't change anything, start and end integers still "-1"
Is there any possibility that to fetch index number of tags?

Thanks in advance.

Deepa Janamatti (RBEI/EMT2) wrote:

> Hi,
>  Sorry, change the below line to
> Document doc = new SAXBuilder().build(new File("<xml file path>"));
>
> -----Original Message-----
> From: Deepa Janamatti (RBEI/EMT2)
> Sent: Thursday, 3. April 2008 9:16 AM
> To: 'deneme.true@...'; jdom-interest@...
> Subject: RE: [jdom-interest] Fetching between two elements
>
> Hi,
>
> Document doc = new Document("<xml file path>");
> Element root = doc.getRootElement();
> //write logic to fetch the "four" tag
> Element fourEle;
> fourEle.getParent().getChild("two");
>
> Regards,
> Deepa
>
> -----Original Message-----
> From: jdom-interest-bounces@... [mailto:jdom-interest-bounces@...] On Behalf Of deneme.true@...
> Sent: Wednesday, 2. April 2008 10:31 PM
> To: jdom-interest@...
> Subject: [jdom-interest] Fetching between two elements
>
> Hi,
>
> I want to parse between two elements. For example:
>
> <root>
> <one>1</one>
> <two>2</two>
> <three>3</three>
> <four>4</four>
> <five>5</five>
> </root>
>
> How can I fetch from 2(<two>2</two>) through 4(<four>4</four>) tag?
>
> Thanks in advance.
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@...
>
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...
LightInTheBox - Buy quality products at wholesale price