XML interview question · Most asked

Your XPath query returns nothing, but the elements are clearly there. What's the likely cause?

Create a free account to save this page, take notes and track your progress. Sign in

Summary

The document has a default namespace, so its elements aren't in 'no namespace'. XPath 1.0 name tests without a prefix only match no-namespace elements. Bind a prefix to the namespace URI and use it in every step (//s:product/s:price). In Java also enable setNamespaceAware(true).

Longer Answer

This is the most common XML bug in integrations: a partner adds a namespace, queries silently return empty results, and an import "succeeds" with zero rows. Alert on unexpected zero counts.

Key Points

  • Default namespace on the document.
  • Prefix + namespace map in the query.
  • Java: namespace-aware factory.
  • Alert on empty results.

Deep dive: XML in Production: The Import That Found Zero Orders

Explanation

What interviewers look for

Namespace diagnosis and a production safeguard.

More most-asked XML questions

← All XML questions

Was this page helpful?