-2

I need a little help in one of the scenario I have. I have this XMl

<catalogOfferID>
   <catalogOfferID>5609805</catalogOfferID>
</catalogOfferID>

I wanted to fetch 5609805 from this as catalogOfferID.

The logic I am using

But the problem is as due to the same name of parent and child tag it is giving me result like <catalogOfferID>5609805

Please help me in solving this problem.

TIA.

Shnugo
  • 66,100
  • 9
  • 53
  • 114
  • 2
    Where is the logic you are using? To me, the result looks legit, apart from the need to cast that string to an integer – Nico Haase Apr 05 '18 at 11:33
  • 1
    @NicoHaase The result seems to be together with the ``, which was not shown due to missing formatting... Found this via *edit*. But the *logic I am using* is not there at all... – Shnugo Apr 05 '18 at 11:58

1 Answers1

2

A quick shot is to use an XPath like this:

//catalogOfferID/catalogOfferID/text()

or

//catalogOfferID[text()]/text()

But what you show is not enough for a serious answer...

UPDATE

After reading your question in edit-mode I found, that you get the result as

<catalogOfferID>5609805

This shows quite clearly, that you are trying to get this on string level between <catalogOfferID> and </catalogOfferID>. You should never!! read XML this way. Use the appropriate XML classes! Read this and this for a start.

Community
  • 1
  • 1
Shnugo
  • 66,100
  • 9
  • 53
  • 114