How to check if a field (multiple occurrence in XML) is having a value from the predefined set of values using Xpath - xpath

I have an XML where I am trying to check following conditions -
If Count of E1KNVVM segments > 0 then do the following, else set false.
If KTOKD = Z002|Z004 - Set false. No need to check VKORG. else check the following
If there is atleast one E1KNVVM segment with VKORG = 1000|1010|1140|1150|1060 - set true.
if all the VKORG = 1140 and KTOKD = Z012|Z013, set false. if all the VKORG = 1140 and KTOKD != Z012|Z013, set true
if all the VKORG = 1060 and KTOKD = Z012|Z013, set false. if all the VKORG = 1060 and KTOKD != Z012|Z013, set true
If KTOKD = Z012|Z013 and there is at least one VKORG = 1000|1010|1150 - set true.
Example data -
```
<?xml version="1.0" encoding="UTF-8"?>
<ZOMI034_DEBMAS07>
<IDOC BEGIN="1">
<E1KNA1M SEGMENT="1">
<MSGFN>005</MSGFN>
<KUNNR>0010015829</KUNNR>
<BBBNR>0000000</BBBNR>
<BBSNR>00000</BBSNR>
<BUBKZ>0</BUBKZ>
<KTOKD>Z012</KTOKD>
<LAND1>CA</LAND1>
<NAME1>Decoration Sherbrooke Inc</NAME1>
<NAME3>Decoration Sherbrooke Inc</NAME3>
<ORT01>Sherbrooke</ORT01>
<PSTLZ>J1J 4L9</PSTLZ>
<REGIO>QC</REGIO>
<SORTL>DECORATION</SORTL>
<SPRAS>E</SPRAS>
<STRAS>739 rue Paul-Desruisseaux</STRAS>
<TELF1>819-566-5585</TELF1>
<TELFX>819-565-0855</TELFX>
<LZONE>J1J</LZONE>
<UMJAH>0000</UMJAH>
<JMZAH>000000</JMZAH>
<JMJAH>0000</JMJAH>
<KATR1>TP</KATR1>
<KATR2>DL</KATR2>
<KATR3>SF</KATR3>
<KATR4>OS</KATR4>
<KATR5>SW</KATR5>
<KATR9>001</KATR9>
<KATR10>074</KATR10>
<UMSA1>0</UMSA1>
<HZUOR>00</HZUOR>
<CIVVE>X</CIVVE>
<SPRAS_ISO>EN</SPRAS_ISO>
<KDKG1>S</KDKG>
<E1KNVVM SEGMENT="1">
<MSGFN>005</MSGFN>
<VKORG>11409</VKORG>
<VTWEG>01</VTWEG>
<SPART>00</SPART>
<VERSG>1</VERSG>
<AUFSD>01</AUFSD>
<KALKS>1</KALKS>
<KDGRP>N</KDGRP>
<BZIRK>SOM014</BZIRK>
<KONDA>ID</KONDA>
<PLTYP>22</PLTYP>
<AWAHR>100</AWAHR>
<INCO1>PPD</INCO1>
<INCO2>Mississauga</INCO2>
<ANTLF>9</ANTLF>
<LPRIO>03</LPRIO>
<VSBED>01</VSBED>
<FAKSD>25</FAKSD>
<WAERS>CAD</WAERS>
<KTGRD>01</KTGRD>
<ZTERM>H013</ZTERM>
<VKGRP>BC1</VKGRP>
<VKBUR>WT</VKBUR>
<KVGR1>ID</KVGR1>
<KVGR2>05</KVGR2>
<KVGR4>FAB</KVGR4>
<KVGR5>NE</KVGR5>
<BOKRE>X</BOKRE>
<PRFRE>X</PRFRE>
<KABSS>ZCCP</KABSS>
<UEBTO>10.0</UEBTO>
<UNTTO>15.0</UNTTO>
<PODTG> 0</PODTG>
<INCO2_L>Mississauga</INCO2_L>
<KALKS_NEW>1</KALKS_NEW>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YG</PARVW>
<KUNN2>0000600419</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YD</PARVW>
<KUNN2>0000600257</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>WE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>AG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YR</PARVW>
<KUNN2>0000600323</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z4</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Y1</PARVW>
<KUNN2>0000107886</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z6</PARVW>
<KUNN2>0000165083</KUNN2>
<KNREF>50166531</KNREF>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z8</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>US</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>CA</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>MX</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
</E1KNVVM>
<E1KNVVM SEGMENT="1">
<MSGFN>005</MSGFN>
<VKORG>1140</VKORG>
<VTWEG>01</VTWEG>
<SPART>00</SPART>
<VERSG>1</VERSG>
<AUFSD>01</AUFSD>
<KALKS>1</KALKS>
<KDGRP>N</KDGRP>
<BZIRK>T00376</BZIRK>
<KONDA>ID</KONDA>
<PLTYP>03</PLTYP>
<AWAHR>100</AWAHR>
<INCO1>PPD</INCO1>
<INCO2>MISSISSAUGA</INCO2>
<ANTLF>9</ANTLF>
<LPRIO>03</LPRIO>
<VSBED>01</VSBED>
<FAKSD>25</FAKSD>
<WAERS>CAD</WAERS>
<KTGRD>01</KTGRD>
<ZTERM>H013</ZTERM>
<VKGRP>Q1</VKGRP>
<VKBUR>QC</VKBUR>
<KVGR1>ID</KVGR1>
<KVGR2>OT</KVGR2>
<KVGR4>FAB</KVGR4>
<KVGR5>NE</KVGR5>
<BOKRE>X</BOKRE>
<PRFRE>X</PRFRE>
<KABSS>ZCCP</KABSS>
<UEBTO>10.0</UEBTO>
<UNTTO>15.0</UNTTO>
<PODTG> 0</PODTG>
<INCO2_L>MISSISSAUGA</INCO2_L>
<KALKS_NEW>1</KALKS_NEW>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YG</PARVW>
<KUNN2>0000600311</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YR</PARVW>
<KUNN2>0000600320</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YD</PARVW>
<KUNN2>0000600256</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>WE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>AG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z4</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Y1</PARVW>
<KUNN2>0000107887</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z8</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>US</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>CA</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>MX</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVVH SEGMENT="1">
<MSGFN>005</MSGFN>
<TDOBJECT>KNVV</TDOBJECT>
<TDNAME>001001582910100100</TDNAME>
<TDID>0001</TDID>
<TDSPRAS>E</TDSPRAS>
<TDSPRASISO>EN</TDSPRASISO>
<E1KNVVL SEGMENT="1">
<MSGFN>005</MSGFN>
<TDFORMAT>*</TDFORMAT>
<TDLINE>TAKE NO ORDERS FROM BRIGETTE LAGACE</TDLINE>
</E1KNVVL>
</E1KNVVH>
</E1KNVVM>
<E1KNVVM SEGMENT="1">
<MSGFN>005</MSGFN>
<VKORG>1192</VKORG>
<VTWEG>01</VTWEG>
<SPART>00</SPART>
<VERSG>1</VERSG>
<AUFSD>01</AUFSD>
<KALKS>1</KALKS>
<KDGRP>N</KDGRP>
<BZIRK>T00376</BZIRK>
<KONDA>ID</KONDA>
<PLTYP>03</PLTYP>
<AWAHR>100</AWAHR>
<INCO1>PPD</INCO1>
<INCO2>MISSISSAUGA</INCO2>
<ANTLF>9</ANTLF>
<LPRIO>03</LPRIO>
<VSBED>01</VSBED>
<FAKSD>25</FAKSD>
<WAERS>CAD</WAERS>
<KTGRD>01</KTGRD>
<ZTERM>H013</ZTERM>
<VKGRP>Q1</VKGRP>
<VKBUR>QC</VKBUR>
<KVGR1>ID</KVGR1>
<KVGR2>OT</KVGR2>
<KVGR4>FAB</KVGR4>
<KVGR5>NE</KVGR5>
<BOKRE>X</BOKRE>
<PRFRE>X</PRFRE>
<KABSS>ZCCP</KABSS>
<UEBTO>10.0</UEBTO>
<UNTTO>15.0</UNTTO>
<PODTG> 0</PODTG>
<INCO2_L>MISSISSAUGA</INCO2_L>
<KALKS_NEW>1</KALKS_NEW>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YG</PARVW>
<KUNN2>0000600311</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YR</PARVW>
<KUNN2>0000600320</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>YD</PARVW>
<KUNN2>0000600256</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>WE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>AG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RG</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>RE</PARVW>
<KUNN2>0010015829</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z4</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Y1</PARVW>
<KUNN2>0000107887</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVPM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARVW>Z8</PARVW>
<KUNN2>0000165083</KUNN2>
<PARZA>000</PARZA>
</E1KNVPM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>US</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>CA</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVIM SEGMENT="1">
<MSGFN>005</MSGFN>
<ALAND>MX</ALAND>
<TATYP>ZITD</TATYP>
<TAXKD>1</TAXKD>
</E1KNVIM>
<E1KNVVH SEGMENT="1">
<MSGFN>005</MSGFN>
<TDOBJECT>KNVV</TDOBJECT>
<TDNAME>001001582910100100</TDNAME>
<TDID>0001</TDID>
<TDSPRAS>E</TDSPRAS>
<TDSPRASISO>EN</TDSPRASISO>
<E1KNVVL SEGMENT="1">
<MSGFN>005</MSGFN>
<TDFORMAT>*</TDFORMAT>
<TDLINE>TAKE NO ORDERS FROM BRIGETTE LAGACE</TDLINE>
</E1KNVVL>
</E1KNVVH>
</E1KNVVM>
<E1KNB1M SEGMENT="1">
<MSGFN>005</MSGFN>
<BUKRS>1222</BUKRS>
<BUSAB>EM</BUSAB>
<AKONT>0000121000</AKONT>
<ZWELS>YZX</ZWELS>
<ZTERM>H013</ZTERM>
<ZINDT>20091201</ZINDT>
<ZINRT>01</ZINRT>
<ZSABE>MIREILLE</ZSABE>
<VLIBB>0</VLIBB>
<VRSZL>0</VRSZL>
<VRSPR>0</VRSPR>
<VERDT>00000000</VERDT>
<XAUSZ>1</XAUSZ>
<WEBTR>0</WEBTR>
<DATLZ>19000101</DATLZ>
<XZVER>X</XZVER>
<KULTG>0</KULTG>
<PERNR>00000000</PERNR>
<INTAD>leblancmir#gmail.com</INTAD>
</E1KNB1M>
<E1KNB1M SEGMENT="1">
<MSGFN>005</MSGFN>
<BUKRS>1227</BUKRS>
<BUSAB>EM</BUSAB>
<AKONT>0000121000</AKONT>
<ZWELS>YZX</ZWELS>
<ZTERM>H013</ZTERM>
<ZINDT>19000101</ZINDT>
<ZINRT>01</ZINRT>
<ZSABE>Mireille L.</ZSABE>
<VLIBB>0</VLIBB>
<VRSZL>0</VRSZL>
<VRSPR>0</VRSPR>
<VERDT>00000000</VERDT>
<XAUSZ>2</XAUSZ>
<WEBTR>0</WEBTR>
<DATLZ>19000101</DATLZ>
<XZVER>X</XZVER>
<KULTG>0</KULTG>
<PERNR>00000000</PERNR>
<INTAD>leblancmir#gmail.com</INTAD>
</E1KNB1M>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000107886</PARNR>
<NAME1>Invoice Recipient 1</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000107887</PARNR>
<NAME1>Invoice Recipient 1</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000107888</PARNR>
<NAME1>Invoice Recipient 1</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000107889</PARNR>
<NAME1>Invoice Recipient 1</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000165083</PARNR>
<NAMEV>General</NAMEV>
<NAME1>Confirmation</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000165084</PARNR>
<NAMEV>General</NAMEV>
<NAME1>Confirmation</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000055761</PARNR>
<NAME1>ACKNOWLEDGMENT</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000055765</PARNR>
<NAME1>ASN</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000055769</PARNR>
<NAME1>INVOICE</NAME1>
<UEPAR>0000000000</UEPAR>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000055773</PARNR>
<NAMEV>JOANIE</NAMEV>
<NAME1>A/P</NAME1>
<UEPAR>0000000000</UEPAR>
<TELF1>819 566 5585</TELF1>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1KNVKM SEGMENT="1">
<MSGFN>005</MSGFN>
<PARNR>0000055778</PARNR>
<NAMEV>LEBLANC</NAMEV>
<NAME1>MIREILLE</NAME1>
<UEPAR>0000000000</UEPAR>
<TELF1>8195665585</TELF1>
<PARLA>E</PARLA>
<GBDAT>00000000</GBDAT>
<VRTNR>0000000000</VRTNR>
<MOAB1>000000</MOAB1>
<MOBI1>000000</MOBI1>
<MOAB2>000000</MOAB2>
<MOBI2>000000</MOBI2>
<DIAB1>000000</DIAB1>
<DIBI1>000000</DIBI1>
<DIAB2>000000</DIAB2>
<DIBI2>000000</DIBI2>
<MIAB1>000000</MIAB1>
<MIBI1>000000</MIBI1>
<MIAB2>000000</MIAB2>
<MIBI2>000000</MIBI2>
<DOAB1>000000</DOAB1>
<DOBI1>000000</DOBI1>
<DOAB2>000000</DOAB2>
<DOBI2>000000</DOBI2>
<FRAB1>000000</FRAB1>
<FRBI1>000000</FRBI1>
<FRAB2>000000</FRAB2>
<FRBI2>000000</FRBI2>
<SAAB1>000000</SAAB1>
<SABI1>000000</SABI1>
<SAAB2>000000</SAAB2>
<SABI2>000000</SABI2>
<SOAB1>000000</SOAB1>
<SOBI1>000000</SOBI1>
<SOAB2>000000</SOAB2>
<SOBI2>000000</SOBI2>
<PARLA_ISO>EN</PARLA_ISO>
</E1KNVKM>
<E1VCKUN SEGMENT="1">
<MSGFN>005</MSGFN>
<CCINS>VISA</CCINS>
<CCNUM>-E803-8027-B7SFF4A0PF716H</CCNUM>
<CCDEF>X</CCDEF>
<CCNAME>Decoration Sherbrooke</CCNAME>
<DATAB>20200131</DATAB>
<DATBI>20231031</DATBI>
<CCTYP>01</CCTYP>
</E1VCKUN>
</E1KNA1M>
</IDOC>
</ZOMI034_DEBMAS07>
I have used the follwoing Xpath -
```boolean(//*:VKORG[.=('1000','1010','1140','1150','1060')]) and boolean(not(//KTOKD= 'Z002') and not(//KTOKD ='Z004')) and boolean(count(//E1KNVVM)>0) and boolean((count(//E1KNVVM[VKORG = '1140']) != count(//E1KNVVM)) and (//KTOKD != 'Z012' or //KTOKD != 'Z013')) and boolean((count(//E1KNVVM[VKORG = '1060']) != count(//E1KNVVM)) and (//KTOKD != 'Z012' or //KTOKD != 'Z013'))```
but it is returning true. Actually, it sohuld return false as the VKORG 11409 and 1192 are not in the set -('1000','1010','1140','1150','1060')
Any help is much appriciated .
Thanks
Sugata

Thanks for clarifying your question!
It's hard to give a proper answer if you don't provide a well-formed XML document as sample input. Nevertheless I'm going to attempt to provide an answer, but bear in mind that because I didn't have a sample input, I wasn't able to actually test any suggestions we provide, so it may well contain errors.
I'm also still not entirely clear on the logic of combining the criteria numbered 3 to 6 in your list. The fact that the XML element names are so cryptic means I've got no real clues from that quarter, and although you say "check the following", it's not clear to me if you need all those following criteria need to be true (i.e. that the clauses should be joined with a logical and operator) or if it's enough for only one of them to be true (in which case they can be combined with an or operator). So you may need to join these things like:
A and B and C and D and E and F
... or maybe you want:
A and B and (C or D or E or F)
... or something else ... I'm not sure. So I'm just going to translate the 6 criteria to XPath expressions and leave you to join them together:
If Count of E1KNVVM segments > 0 then do the following, else set false.
//E1KNVVM
this expression will return a sequence of E1KNVVM elements, and when you combine it with the other criteria using a boolean operator, it will be implicitly converted to a boolean value: an empty sequence will return false while a sequence of at least one element will yield the value true.
If KTOKD = Z002|Z004 - Set false. No need to check VKORG. else check the following
//KTOD=('Z002', 'Z004')
This expression will create a sequence of all the KTOD elements in the document, and compare that sequence with the sequence ('Z002', 'Z004'). Because the items in the second sequence are strings, the = comparison will cause the elements in the first sequence to be converted to strings, in order to be comparable to the items in the second sequence. The = comparison will return true if there is at least one pair of items in the two sequences which are judged to be equal; e.g. ('A', 'B') = ('B', 'C') is true. For details about using the = operator used to compare sequences, see the section on "General Comparisons" in the XPath 2.0 spec: https://www.w3.org/TR/xpath20/#id-general-comparisons
If there is atleast one E1KNVVM segment with VKORG = 1000|1010|1140|1150|1060 - set true.
//E1KNVVM\VKORG=('1000', '1010', '1140', '1150', '1060')
if all the VKORG = 1140 and KTOKD = Z012|Z013, set false.
if all the VKORG = 1140 and KTOKD != Z012|Z013, set true
The following expression tests the following:
At least one VKORG is not equal to 1140, OR,
there is at least one KTOKD which is neither Z012 nor Z013
//VKORG != '1140' or //KTOKD[not(. = ('Z012', 'Z013')]
This expression creates a sequence of all the VKORG elements and checks that there's at least one VKORG whose value is not equal to 1140.
The second part of the expression //KTOKD[not(. = ('Z012', 'Z013')] creates a sequence of all the KTOKD elements, and filters it to include only those which are not equal to either one of the strings Z012 and Z013.
NOTE this is different to //KTOKD != ('Z012', 'Z013') which would be true if every KTOKD was not equal to at least one of Z012 or Z013; of course if there were a KTOKD whose value was Z012 it would be != Z013, and if its value were Z013 then it would be != Z012. So //KTOKD != ('Z012', 'Z013') would always return true, so long as there was at least one KTOKD element, no matter what its text value is.
if all the VKORG = 1060 and KTOKD = Z012|Z013, set false. if all the VKORG = 1060 and KTOKD != Z012|Z013, set true
not(//VKORG != '1060') and not(//KTOKD = ('Z012', 'Z013'))
The first part of this expression creates a sequence of all the VKORG elements, and returns true if there are any whose text value is not 1060, and false if there are none whose value is not 1060; in other words it returns false if they are all 1060. The not() function then negates that boolean value, meaning that if they're all 1060 the result is true.
As an aside, in XPath version 3 there's some new syntax which allows this kind of condition to be written in a more readable way: every $v in //VKORG satisfies $v = '1060', but that's no help if you're stuck using XPath 2.
The second part of the expression is the same as in the previous criterion.
If KTOKD = Z012|Z013 and there is at least one VKORG = 1000|1010|1150 - set true.
//KTOKD = ('Z012', 'Z013') and //VKORG = ('1000', '1010', '1150')
Good luck! I hope this helps!

Related

XSLT copy then sort element, duplicates sorted element

I am trying to sort the E1EDK33 element by "TSRFO_CONSIGNEE" However when doing so I get the original E1EDK33 elements plus the newly sorted elements in the end.
Here is my example file:
<SHPMNT06>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
</EDI_DC40>
<E1EDT20 SEGMENT="1">
<DeliveryStops>6</DeliveryStops>
<E1EDT22 SEGMENT="1">
<VSART_BEZ>LKW</VSART_BEZ>
</E1EDT22>
<E1EDK33 SEGMENT="1">
<TSNUM>0001</TSNUM>
<TSRFO>0001</TSRFO>
<TSRFO_CONSIGNEE>0003</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0002</TSNUM>
<TSRFO>0002</TSRFO>
<TSRFO_CONSIGNEE>0002</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0003</TSNUM>
<TSRFO>0003</TSRFO>
<TSRFO_CONSIGNEE>0001</TSRFO_CONSIGNEE>
</E1EDK33>
<E1ETD01 SEGMENT="1">
<DGMDDAT>20220321</DGMDDAT>
</E1ETD01>
</E1EDT20>
</IDOC>
</SHPMNT06>
my xslt file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/>
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="E1EDT20">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:apply-templates select="*"/>
<xsl:apply-templates select="E1EDK33">
<xsl:sort select="TSRFO_CONSIGNEE" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Result file:
<SHPMNT06>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
</EDI_DC40>
<E1EDT20 SEGMENT="1">
<DeliveryStops>6</DeliveryStops>
<E1EDT22 SEGMENT="1">
<VSART_BEZ>LKW</VSART_BEZ>
</E1EDT22>
<E1EDK33 SEGMENT="1">
<TSNUM>0001</TSNUM>
<TSRFO>0001</TSRFO>
<TSRFO_CONSIGNEE>0003</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0002</TSNUM>
<TSRFO>0002</TSRFO>
<TSRFO_CONSIGNEE>0002</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0003</TSNUM>
<TSRFO>0003</TSRFO>
<TSRFO_CONSIGNEE>0001</TSRFO_CONSIGNEE>
</E1EDK33>
<E1ETD01 SEGMENT="1">
<DGMDDAT>20220321</DGMDDAT>
</E1ETD01>
<E1EDK33 SEGMENT="1">
<TSNUM>0003</TSNUM>
<TSRFO>0003</TSRFO>
<TSRFO_CONSIGNEE>0001</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0002</TSNUM>
<TSRFO>0002</TSRFO>
<TSRFO_CONSIGNEE>0002</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0001</TSNUM>
<TSRFO>0001</TSRFO>
<TSRFO_CONSIGNEE>0003</TSRFO_CONSIGNEE>
</E1EDK33>
</E1EDT20>
</IDOC>
</SHPMNT06>
What I want to see is this:
<SHPMNT06>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
<TABNAM>EDI_DC40</TABNAM>
</EDI_DC40>
<E1EDT20 SEGMENT="1">
<DeliveryStops>6</DeliveryStops>
<E1EDT22 SEGMENT="1">
<VSART_BEZ>LKW</VSART_BEZ>
</E1EDT22>
<E1EDK33 SEGMENT="1">
<TSNUM>0003</TSNUM>
<TSRFO>0003</TSRFO>
<TSRFO_CONSIGNEE>0001</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0002</TSNUM>
<TSRFO>0002</TSRFO>
<TSRFO_CONSIGNEE>0002</TSRFO_CONSIGNEE>
</E1EDK33>
<E1EDK33 SEGMENT="1">
<TSNUM>0001</TSNUM>
<TSRFO>0001</TSRFO>
<TSRFO_CONSIGNEE>0003</TSRFO_CONSIGNEE>
</E1EDK33>
<E1ETD01 SEGMENT="1">
<DGMDDAT>20220321</DGMDDAT>
</E1ETD01>
</E1EDT20>
</IDOC>
</SHPMNT06>
I have tried to exclude E1EDK33 from the select <xsl:apply-templates select="*"/> like this: <xsl:apply-templates select="*/*[not(E1EDK33)]"/> and a lot of other permutations but I can't seem to get rid of the duplicated E1EDK33. Either it completely messes up my file or it duplicates it.
You could do
<xsl:template match="E1EDT20">
<xsl:copy>
<xsl:apply-templates select="#*"/>
<xsl:apply-templates select="E1EDK33[1]/preceding-sibling::*"/>
<xsl:apply-templates select="E1EDK33">
<xsl:sort select="TSRFO_CONSIGNEE" data-type="number" order="ascending"/>
</xsl:apply-templates>
<xsl:apply-templates select="E1EDK33[last()]/following-sibling::*"/>
</xsl:copy>
</xsl:template>
To exclude E1EDK33 elements in your select statement, you could use the self axis like so: *[not(self::E1EDK33)]

Specifying multiple ids (AlternateId ) in the ConvertId EWS request?

I was under an impression that I can pass multiple ids in the ConvertId request. If I send the following request with two ids (they happen to be folder and its child message), I only get one id back.
Sure sounds like a bug...
Request:
<?xml version="1.0" encoding="ISO-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<m:ConvertId DestinationFormat="EwsId">
<m:SourceIds>
<AlternateId Format="EntryId" Id="AAAAAF6BdU8APhVJsGWfKuqS58IBAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAA==" Mailbox="user#domain.demo"/>
<AlternateId Format="EntryId" Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCqPL+oKLEAAeNW8FMAAA==" Mailbox="user#domain.demo"/>
</m:SourceIds>
</m:ConvertId>
</soap:Body>
</soap:Envelope>
And the response is
<?xml version="1.0" encoding="ISO-8859-1"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" Version="V2018_01_08" MinorBuildNumber="31" MajorBuildNumber="1228" MinorVersion="20" MajorVersion="15"/>
</s:Header>
<s:Body>
<m:ConvertIdResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<m:ResponseMessages>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId Mailbox="user#domain.demo" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQAB41bwUwAAAA==" Format="EwsId" xsi:type="t:AlternateIdType"/>
</m:ConvertIdResponseMessage>
</m:ResponseMessages>
</m:ConvertIdResponse>
</s:Body>
</s:Envelope>
EDIT:
An example of two ids (two messages) request worling as expected.
Request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<ConvertId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
DestinationFormat="EwsId">
<SourceIds>
<t:AlternateId Format="EntryId"
Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCqPL+oKLEAAiLXM0AAAA=="
Mailbox="user#domain.demo"/>
<t:AlternateId Mailbox="user#domain.demo"
Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCq PL+oKLEAAiC+eEMAAA=="
Format="EntryId"/>
</SourceIds>
</ConvertId>
Response:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1273" MinorBuildNumber="26" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header><s:Body><m:ConvertIdResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId xsi:type="t:AlternateIdType" Format="EwsId" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQACItczQAAAAA==" Mailbox="user#domain.demo"/>
</m:ConvertIdResponseMessage>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId xsi:type="t:AlternateIdType" Format="EwsId" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQACIL54QwAAAA==" Mailbox="user#domain.demo"/>
</m:ConvertIdResponseMessage>
</m:ResponseMessages>
</m:ConvertIdResponse>
</s:Body>
</s:Envelope>
Corrections
So, consolidating our exchange so it can be seen as the answer to date.
As per the sanity testing of this method by myself and Dmitry Streblechenko (the OP). In leveraging this method, multiples are allowed.
For example: only one type (messages) or another (folders) is allowed at the same time.

How to retrieve all changed folders from the root public folder via EWS?

I need to get all public folders when a user changes permissions or items in a folder. How to do it? I can not find the proper answer in the documentation.
I only found this:
POST outlook.office365.com/EWS/Exchange.asmx
?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<m:SyncFolderHierarchy>
<m:FolderShape>
<t:BaseShape>IdOnly</t:BaseShape>
</m:FolderShape>
<m:SyncFolderId>
<t:DistinguishedFolderId Id="publicfoldersroot" />
</m:SyncFolderId>
</m:SyncFolderHierarchy>
</soap:Body>
</soap:Envelope>
and the response is:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1207" MinorBuildNumber="28" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:SyncFolderHierarchyResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:SyncFolderHierarchyResponseMessage ResponseClass="Error">
<m:MessageText>The root of a folder hierarchy synchronization cannot be set to the id of a public folder. Use FindFolder to synchronize the public folder hierarchy.</m:MessageText>
<m:ResponseCode>ErrorInvalidOperation</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:SyncState/>
<m:IncludesLastFolderInRange>true</m:IncludesLastFolderInRange>
</m:SyncFolderHierarchyResponseMessage>
</m:ResponseMessages>
</m:SyncFolderHierarchyResponse>
</s:Body>
</s:Envelope>
As you can see it does not work.

How to properly create/update public folder via EWS using admin impersonation?

I cannot create any public folder in case when I set proper permission (through WebUI) to that user (in my case admin).
But when I try to update public folder`s 'EffectiveRights' to add permission level to that user I cannot do it. Which request I need to send to update user permission level on public folder or add proper 'EffectiveRights' on that public folder?
Example of the request:
POST outlook.office365.com/EWS/Exchange.asmx
Content-Type:text/xml; charset=utf-8
Accept:text/xml; charset=utf-8
BODY
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<UpdateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderChanges>
<t:FolderChange>
<t:DistinguishedFolderId Id="publicfoldersroot" />
<t:Updates>
<t:SetFolderField>
<t:FieldURI FieldURI="folder:EffectiveRights"/>
<t:Folder>
<t:EffectiveRights>
<t:CreateAssociated>false</t:CreateAssociated>
<t:CreateContents>true</t:CreateContents>
<t:CreateHierarchy>false</t:CreateHierarchy>
<t:Delete>false</t:Delete>
<t:Modify>false</t:Modify>
<t:Read>true</t:Read>
</t:EffectiveRights>
</t:Folder>
</t:SetFolderField>
</t:Updates>
</t:FolderChange>
</FolderChanges>
</UpdateFolder>
</soap:Body>
</soap:Envelope>
and the response is:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1164" MinorBuildNumber="25" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:UpdateFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:UpdateFolderResponseMessage ResponseClass="Error">
<m:MessageText>Set action is invalid for property.</m:MessageText>
<m:ResponseCode>ErrorInvalidPropertySet</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:MessageXml>
<t:FieldURI FieldURI="folder:EffectiveRights"/>
</m:MessageXml>
<m:Folders/>
</m:UpdateFolderResponseMessage>
</m:ResponseMessages>
</m:UpdateFolderResponse>
</s:Body>
</s:Envelope>
another one example:
POST outlook.office365.com/EWS/Exchange.asmx
Content-Type:text/xml; charset=utf-8
Accept:text/xml; charset=utf-8
BODY
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<m:UpdateFolder>
<m:FolderChanges>
<t:FolderChange>
<t:FolderId Id="AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwCOXNGsJPKoS5iTrqfBNvbzAACDSr4rAAA=" />
<t:Updates>
<t:SetFolderField>
<t:FieldURI FieldURI="folder:PermissionSet" />
<t:Folder>
<t:PermissionSet>
<t:Permissions>
<t:Permission>
<t:UserId>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:UserId>
<t:PermissionLevel>Editor</t:PermissionLevel>
</t:Permission>
</t:Permissions>
</t:PermissionSet>
</t:Folder>
</t:SetFolderField>
</t:Updates>
</t:FolderChange>
</m:FolderChanges>
</m:UpdateFolder>
</soap:Body>
</soap:Envelope>
and the response:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1143" MinorBuildNumber="18" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:UpdateFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:UpdateFolderResponseMessage ResponseClass="Error">
<m:MessageText>Access is denied. Check credentials and try again., Underlying MAPI stream threw exception</m:MessageText>
<m:ResponseCode>ErrorAccessDenied</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:Folders/>
</m:UpdateFolderResponseMessage>
</m:ResponseMessages>
</m:UpdateFolderResponse>
</s:Body>
</s:Envelope>
Because your trying to create folders in publicfoldersroot no user has rights by default to do that (this is to stop people messing up the Public Folder root). So if you want your user test#test_test.onmicrosoft.com you would need to first grant them rights to do that on the Root folder either using the EAC or Add-PublicFolderclientPermissions. I would suggest you first create a folder in the Root using the EAC and then get your code to create child folders of that, from a development point of view this is easier to cleanup when you need to delete everything and test again then trying to clear the whole root hierarchy each time.
Also only you second example will work because EffectiveRights is a calculate property so can't be updated, all you can do is update the underlying DACL of the folder which is what you second request is doing

XML digital signature. How to add ds namespace to Signature node using signer gem?

I need to envelope xml in soap message, digest data from original xml and sign it. Actual algorithm of signing or digesting does not matter for now.
Example of original xml:
<TransferMsg>
<Data>Super Important Data</Data>
</TransferMsg>
Final result must be something like that:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="CertId">MIIIRzCCB/agAwIBAgIKSchnBgAAAAGKvDAIBgYqhQMCAgMwggFOMRgwFgYFKoUDZAESDTEwMjc3MDcwMTM4MDYxGjAYBggqhQMDgQMBARIMMDA3NzA3MzE0MDI5MTwwOgYDVQQJDDPQkS7QodGD0YXQsNGA0LXQstGB0LrQuNC5INC/0LXRgCzQtDExLNGB0YLRgDEs0L7RhDYxIzAhBgkqhkiG9w0BCQEWFGUtbW9za3ZhQGUtbW9za3ZhLnJ1MQswCQYDVQQGEwJSVTEcMBoGA1UECAwTNzcg0LMuINCc0L7RgdC60LLQsDEVMBMGA1UEBwwM0JzQvtGB0LrQstCwMTUwMwYDVQQKDCzQntCQ0J4gItCt0LvQtd=</wsse:BinarySecurityToken>
<ds:Signature>
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"/>
</ds:SignedInfo>
<ds:SignatureValue>vnjz04yWa7DbRtC5vJAt/tsCR5m31i3e8FMxG2eOIo4DtsGhm1FgZ8wKLEEzvbYuolrosc2OKkFafqJinsTWsg==</SignatureValue>
<ds:KeyInfo>
<wsse:SecurityTokenReference>
<wsse:Reference URI="#CertId" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</wsse:SecurityTokenReference>
</ds:KeyInfo>
</Signature>
</wsse:Security>
</soap:Header>
<soap:Body wsu:Id="body">
<soap:TransferMsg>
<soap:DataToDigest>Super Important Data</soap:DataToDigest>
</soap:TransferMsg>
</soap:Body>
</soap:Envelope>
Right now I'm using signer builtin sign! and digest! methods like this:
require 'openssl'
require 'signer'
class MySigner
def initialize
#soap_envelope = File.open('./data/soap_envelope.xml') { |f| Nokogiri::XML(f) }
end
def sign(xml_to_sign)
signer = Signer.new(put_in_envelope(xml_to_sign))
signer.cert = OpenSSL::X509::Certificate.new(File.read("./data/cert.pem"))
signer.private_key = OpenSSL::PKey.read(File.read("./data/key.pem"), "PASSWORD")
signer.security_token_id = 'CertId'
namespaces = {
'soap' => 'http://schemas.xmlsoap.org/soap/envelope/',
'ds' => 'http://www.w3.org/2000/09/xmldsig#'
}
# Digest soap:Body tag
signer.document.xpath('//TransferMsg', namespaces).each do |node|
signer.digest!(node, id: 'body')
end
# Sign document itself
signer.sign!(security_token: true, enveloped: true)
signer.to_xml
end
def put_in_envelope(xml)
xml_object = Nokogiri::XML(xml)
valuable_data = xml_object.xpath('/TransferMsg').to_s
#soap_envelope.xpath('//soap:Body').children.first.add_next_sibling(valuable_data)
#soap_envelope
end
end
soap_envelope.xml:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
</wsse:Security>
</soap:Header>
<soap:Body wsu:Id="body">
</soap:Body>
</soap:Envelope>
But resulted code has <Signature xmlns='http://www.w3.org/2000/09/xmldsig#'> instead of <ds:Signature>:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="CertId">MIIIRzCCB/agAwIBAgIKSchnBgAAAAGKvDAIBgYqhQMCAgMwggFOMRgwFgYFKoUDZAESDTEwMjc3MDcwMTM4MDYxGjAYBggqhQMDgQMBARIMMDA3NzA3MzE0MDI5MTwwOgYDVQQJDDPQkS7QodGD0YXQsNGA0LXQstGB0LrQuNC5INC/0LXRgCzQtDExLNGB0YLRgDEs0L7RhDYxIzAhBgkqhkiG9w0BCQEWFGUtbW9za3ZhQGUtbW9za3ZhLnJ1MQswCQYDVQQGEwJSVTEcMBoGA1UECAwTNzcg0LMuINCc0L7RgdC60LLQsDEVMBMGA1UEBwwM0JzQvtGB0LrQstCwMTUwMwYDVQQKDCzQntCQ0J4gItCt0LvQtd=</wsse:BinarySecurityToken>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"/>
</SignedInfo>
<SignatureValue>vnjz04yWa7DbRtC5vJAt/tsCR5m31i3e8FMxG2eOIo4DtsGhm1FgZ8wKLEEzvbYuolrosc2OKkFafqJinsTWsg==</SignatureValue>
<KeyInfo>
<wsse:SecurityTokenReference>
<wsse:Reference URI="#CertId" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
</wsse:SecurityTokenReference>
</KeyInfo>
</Signature>
</wsse:Security>
</soap:Header>
<soap:Body wsu:Id="body">
<soap:TransferMsg>
<soap:DataToDigest>Super Important Data</soap:DataToDigest>
</soap:TransferMsg>
</soap:Body>
</soap:Envelope>
Of course I can manually change Signature node namespace and remove xmlns with nokogiri, but I prefer more automatic way to do it. Am I missing something in the docs?

Resources