0

I am using java Xml Xpath , I have a XML inside it there is a table something like this

      <oasis:table frame="topbot">
          <oasis:tgroup cols="6">
            <oasis:colspec colwidth="*" colnum="1" colname="col1" align="left" />
            <oasis:colspec colwidth="*" colnum="2" colname="col2" align="char" char="." />
            <oasis:colspec colwidth="*" colnum="3" colname="col3" align="left" />
            <oasis:colspec colwidth="*" colnum="4" colname="col4" align="left" />
            <oasis:colspec colwidth="*" colnum="5" colname="col5" align="left" />
            <oasis:colspec colwidth="*" colnum="6" colname="col6" align="char" char="." />
            <oasis:thead>
                <oasis:row rowsep="1">
                    <oasis:entry colname="col1" />
                    <oasis:entry colname="col2" align="center">Age</oasis:entry>
                    <oasis:entry colname="col3" align="center">Education</oasis:entry>
                    <oasis:entry colname="col4" align="center">Occupation</oasis:entry>
                    <oasis:entry colname="col5" align="center">SES</oasis:entry>
                    <oasis:entry colname="col6" align="center">ID</oasis:entry>
                </oasis:row>
            </oasis:thead>
            <oasis:tbody>
                <oasis:row>
                    <oasis:entry colname="col1">Suzan</oasis:entry>
                    <oasis:entry colname="col2">29</oasis:entry>
                    <oasis:entry colname="col3">Bachelors</oasis:entry>
                    <oasis:entry colname="col4">Homemaker</oasis:entry>
                    <oasis:entry colname="col5">Moderate</oasis:entry>
                    <oasis:entry colname="col6">2.01</oasis:entry>
                </oasis:row>
          </oasis:tbody>
        </oasis:tgroup>
     </oasis:table>

I want to parse "oasis:" tag from everywhere. I tried using NamespaceContext but it did not work.I tried "oasis" as prefix but I am not able to achieve it. Any idea how to remove these "oasis:" from everywhere in the table

Lokesh
  • 51
  • 1
  • 9

1 Answers1

1

With XPath, you can select all oasis nodes with :

//*[contains(name(),"oasis")]
E.Wiest
  • 5,425
  • 2
  • 7
  • 12
  • @EWiest Is there a way to prefix everythig with oasis – Lokesh Apr 07 '20 at 14:59
  • What do you mean with "prefix everything with oasis" ? Adding something before (like `foo:oasis:entry` ? If i fully understand, you want to remove oasis namespace. Your best bet is probably to use XSLT. Take a look at @Syam S's answer : https://stackoverflow.com/a/25033784/9978746 – E.Wiest Apr 07 '20 at 15:59
  • @hey it worked its removing oasis namespace but its all other namespaces too...I don't want that I want only oasis namespace to be removed – Lokesh Apr 07 '20 at 18:33
  • I'm not a Java expert but you can try to replace this part `` with `` and this part `` with ``. – E.Wiest Apr 08 '20 at 03:07
  • I tried with 2 namespaces in your sample data and get an expected output (remove oasis, keep foo). http://xsltransform.net/gVK9Hpf – E.Wiest Apr 08 '20 at 11:07