0
votes

I have an xml with the following structure

<?xml version="1.0" encoding="UTF-8"?>
<MYXML>
 <?source-system-command name="abc"?>
  <NAME></NAME>
  <REQUEST>request</REQUEST>
</MYXML>

I want to get the REQUEST TAG Extracted out - the Xquery is /MYXML/REQUEST and I get <Request></Request> Tag

However, now I want the REQUEST tag to be stripped off the MYXML

so the output i am looking for is

<?xml version="1.0" encoding="UTF-8"?>
    <MYXML>
     <?source-system-command name="abc"?>
      <NAME></NAME> >!-- NO REQUEST -->          
    </MYXML>

I wrote the following XQUERY - "/MYXML/*[not(self::REQUEST)]" but this filtersthe processing instruction <?source-system-command name="abc"?>

What am i missing ? How to tell the XQUERY Not to filter out processing instruction ?

Using SAXON-HE 9

1

1 Answers

3
votes

With /MYXML/*[not(self::REQUEST)] you select only element nodes so you would need at least /MYXML/node()[not(self::REQUEST)] or (more XPath 2/3, XQuery like and a bit closer to normal language use) /MYXML/(node() except REQUEST). Note however that all those attempts only select those children of the MYXML root element but not that root element itself, you would need to reconstruct it with e.g.

<MYXML>{/MYXML/(node() except REQUEST)}</MYXML>

or

/*!element {name()} { node() except REQUEST }

as in https://xqueryfiddle.liberty-development.net/pPgCcom