4

I have simillar problem to others trying to search with xPath through XML with two namespaces but still looking on other topics it dosen't seem to work:

XML:

<?xml version="1.0" encoding="utf-8"?>
<IE515 xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.mf.gov.pl/xsd/ECS/IE515_v1-0.xsd" NrWlasny=""
   EmailPodmiotu="">
   <Zgloszenie UCWywozu="" UCWyprowadzenia="PL441010"
      P1a="EX" P1b="A" LiczbaPozycji="" LiczbaOpakowan="" CRN=""
      KrajWysylki="" KrajPrzeznaczenia="" Kontenery="0" MasaBrutto="">
      <Nadawca TIN="" Nazwa="" UlicaNumer="" KodPocztowy="" Miejscowosc=""
         Kraj="" EORI=""/>
      <Odbiorca Nazwa="" UlicaNumer="" KodPocztowy=""
         Miejscowosc="" Kraj=""/>
      <ZglaszajacyPrzedstawiciel KodPocztowy=""
         Miejscowosc="" Kraj="" Nazwa="" TIN="" EORI="" UlicaNumer=""
         Wskaznik="00300" Przedstawicielstwo="1"/>
      <TransportWewnetrzny
         Rodzaj="5"/>
      <TransportNaGranicy Rodzaj="4" Znaki="SAMOLOT"
         Kraj="DE"/>
      <Lokalizacja UC=""/>
      <WarunkiDostawy Kod=""
         MiejsceKod="" Miejsce=""/>
      <Transakcja Waluta="" Wartosc=""
         Kurs=""/>
      <MiejsceData Miejsce="" NazwiskoImie="" Telefon=""
         Data=""/>
      <Towar Nr="1" OpisTowaru="TestName" KodTowarowy="30000" KodTaric="00"
         KrajPochodzenia="PL" ProceduraWnioskowana="10"
         ProceduraPoprzednia="00" MasaNetto="1.4">
         <IloscTowaru Jm="NAR"
            KwalifikatorJm="G" Ilosc="8"/>
         <Opakowanie Rodzaj="PA" Znaki=","
            LiczbaOpakowan="2"/>
         <KodDodatkowyUE Kod="4099"/>
         <DokumentWymagany
            Kod="9DK8" Nr="Oswiadczenie"/>
         <DokumentWymagany Kod="N380"
            Nr="OUT1"></DokumentWymagany>
         <DokumentWymagany Kod="Y903"
            Nr=","/>
         <DokumentWymagany Kod="Y935" Nr=","/>
         <DokumentWymagany
            Kod="Y922" Nr=","/>
         <InformacjaDodatkowa Kod="30400"/>
         <WartoscTowaru
            Waluta="PLN" WartoscStatystyczna="953">
            <Korekta Kod="1STW"
               Wartosc="-200"/>
         </WartoscTowaru>
      </Towar>
   </Zgloszenie>
</IE515>

in my code I'm trying to set NameSpace propoerty like this:

xmlNameSpaces = "xmlns='http://www.mf.gov.pl/xsd/ECS/IE515_v1-0.xsd' xmlns:ds='http://www.w3.org/2000/09/xmldsig#'"
doc.setProperty "SelectionNamespaces", xmlNameSpaces

and then try to search for the specific node, but it dosen't find the node:

Set oAttribute = doc.SelectSingleNode("/IE515/Zgloszenie/Towar[1]/@OpisTowaru")`

Can you explain how the namespace propperty should look like to make it work? I can do this if I have onl

2
  • 1
    "I can do this if I have onl...", would you mind completing your sentence? Commented Apr 20, 2015 at 12:49
  • sorry something was cut out, it works when I remove te second namesamece: xmlns="http://www.mf.gov.pl/xsd/ECS/IE515_v1-0.xsd but when i have two, it dosen't :/ Commented Apr 27, 2015 at 9:27

1 Answer 1

4

You need to assign prefix to the namespace when setting SelectionNamespaces property, so that you can use the prefix in your xpath later on :

xmlNameSpaces = "xmlns:d='http://www.mf.gov.pl/xsd/ECS/IE515_v1-0.xsd'"
doc.setProperty "SelectionNamespaces", xmlNameSpaces

Set oAttribute = doc.SelectSingleNode("/d:IE515/d:Zgloszenie/d:Towar[1]/@OpisTowaru")

Notice prefix d: in above xpath corresponds to the xmlns:d in xmlNameSpaces.

Sign up to request clarification or add additional context in comments.

3 Comments

This dosen't work :/ it only works when I modify xml (only for testing) by adding prefix to the sceond namespace like for example S, then it works fine <IE515 xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:s="http://www.mf.gov.pl/xsd/ECS/IE515_v1-0.xsd" NrWlasny="" EmailPodmiotu=""> but i can't change the xml..
Hi @user3313162 please, look closely at the answer again. No need to change your XML, you only need to add prefix in xmlNameSpaces variable, and to the xpath in SelectSingleNode() parameter.
If eventually you still unable get it to work, please post your updated code showing how you exactly tried to implement the suggested solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.