Question: I have a large XML file, following the structure below:

```
  <processo numero="XXXXX" data-deposito="XXXXX">
    <despachos>
      <despacho codigo="XXXXX" nome="DATA TO GET"/>
    </despachos>
    <titulares>
      <titular nome-razao-social="XXXXX" pais="XX" uf="XX"/>
    </titulares>
    <marca apresentacao="XXXXX" natureza="XXXXX">
      <nome>NAME TO FIND</nome>
    </marca>
    <lista-classe-nice>
      <classe-nice codigo="XX">
        <especificacao>XXXXXXXXXX</especificacao>
        <status>XXXXX</status>
      </classe-nice>
    </lista-classe-nice>
  </processo>

```

And I'm using the following python code to search and print the specific data.

```
from lxml import etree

with open("XML-FILE.xml",'rb') as f:
  file_content = f.read()
  tree = etree.fromstring(file_content)
# get all customer records
  customers = tree.xpath('//processo')
  for customer in customers:
      # note that xpath on text() returns a list
    despacho = customer.xpath('/despachos/despacho/text()')[0]
    nome = customer.xpath('/marca/nome/text()')[0]
    print(nome)
    print(despacho)

```

I'm trying to search in the file the data that have `NAME TO FIND` that is under `<marca`, and after that print data that is inside

```
    <despachos>
      <despacho codigo="XXXXX" nome="DATA TO GET"/>
    </despachos>

```

The problem is that I'm not getting any data, sometimes getting the IndexError: list index out of range error.

Any help is appreciated!

Answer: 
I recommend you a simple library. Before use, you need to install: pip install -U simplified\_scrapy

```
from simplified_scrapy import SimplifiedDoc

doc = SimplifiedDoc()
doc.loadFile('XML-FILE.xml',lineByline=True)

customers = doc.getIterable('processo')
for customer in customers:
    despacho = customer.select('despachos>despacho>nome()')
    nome = customer.select('marca>nome>text()')
    print(despacho)
    print(nome)

```

Result:

```
DATA TO GET
NAME TO FIND

```
Try this XPath:

```
//processo[.//marca/nome[text()='NAME TO FIND']]//despacho/text

```

In case there are several texts matching this XPath you will have to treat it correspondingly.