0

I have an XML like the one below, but this is only a part of a bigger file.

example 1

<EFACT_D96A_INVOIC>
  <NADLoop1>
    <NAD NAD09="SE" NAD08="111 11" NAD07="" NAD06="CITY" NAD01="DP">
      <C082 C08203="9" C08202="" C08201="7350015610088"/>
      <C058 C05801="TESTNAME"/>
      <C080 C08001=""/>
      <C059 C05901="TESTSTREET 35"/>
    </NAD>
  </NADLoop1>
</EFACT_D96A_INVOIC>

example 2

<EFACT_D96A_INVOIC>
  <NADLoop1>
    <NAD NAD09="SE" NAD08="111 11" NAD07="" NAD06="CITY" NAD01="DP">
      <C082 C08203="9" C08202="" C08201="7350015610088"/>
      <C058 C05801=""/>
      <C080 C08001="TESTNAME"/>
      <C059 C05901="TESTSTREET 35"/>
    </NAD>
  </NADLoop1>
</EFACT_D96A_INVOIC>

I want to make an XPath expression that returns the value of either the attribute C05801 if not empty or C08001. Is that possible to do with a oneline XPath?

1 Answer 1

1

What about this. You return both values (if they exists) and just take first one.

/EFACT_D96A_INVOIC/NADLoop1/NAD/*[@C05801!="" or @C08001!=""][1]
Sign up to request clarification or add additional context in comments.

5 Comments

I dont think you read my question correctly. I wanted to have either the value of C05801 or C08001 depending on which is filled out. The fact that the above XML sample has the C05801 filled out doesnt make your suggestion any helpful.
what version of xPath do you use 1 or 2?
I think it is xPath 1
What about solution when you return both values, and just take 1-st one? Would it suite you?
Nice! That really was a slick 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.