Skip to content
Advertisement

Parse HTML table with Oracle

I need to parse an HTML table:

and as a result to get:

I tried to do it like this:

But this causes an exception:

ORA-19279: XPTY0004 – XQuery dynamic type mismatch: expected singleton sequence – got multi-item sequence

What do I need to do to fix my code?

Advertisement

Answer

Your path is looking for a td under the tr; but there are two, hence the “got multi-item sequence” error you’re seeing. You can reference each td tag by its position, as td[1] etc. It’s very reliant on the table structure being as expected though.

With this specific example you can do:

which gets:

It won’t take much variation in the HTML to break it though. See this answer for some reasons it is fragile, and why it generally considered unwise to try to parse HTML as XML.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement