0

I am selecting nodes using XPathDocument from XML containing namespaces. Appropriate namespace has been added:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
nsmgr.AddNamespace("nsABC", @"http://www.thesite.com/xsd/XYZ123.xsd");

Once selecting a node using Select("XPathExpression"):

  1. Will xsd file be download from the external server each time the Select method is executed?
  2. Will xsd file be downloaded once and cached during app life-time, or in the system?

Providing wrong URI in nsmgr.AddNamespace, casues Select to NOT recognise nodes, so this is a proof that it has to be aware of xsd file, thus it had to be downloaded.

  1. What about running app for the first time on other PC without internet access, where there is no chance to have this xsd cached anywhere. Where 'xsd' was is taken from? I have tested this option and code was executed properly.
Megrez7
  • 1,423
  • 1
  • 15
  • 35

1 Answers1

1

To answer all of your three questions at once: No. The .xsd file will not be downloaded - neither on the first run nor on the following runs. By adding the namespace URI with

nsmgr.AddNamespace("nsABC", @"http://www.thesite.com/xsd/XYZ123.xsd");

you merely create a link between the namespace prefix and the namespace URI. The latter is defined as

The attribute's value, a URI reference, is the namespace name identifying the namespace. The namespace name, to serve its intended purpose, should have the characteristics of uniqueness and persistence. It is not a goal that it be directly usable for retrieval of a schema (if any exists). An example of a syntax that is designed with these goals in mind is that for Uniform Resource Names [RFC2141]. However, it should be noted that ordinary URLs can be managed in such a way as to achieve these same goals.

Downloading and validating an XML against an XSD schema has to be done separately. An example using XmlDocument is "Validating an XML against referenced XSD in C#".

zx485
  • 28,498
  • 28
  • 50
  • 59
  • Clear, so why it does not work (recognise nodes) once URI points to wrong / not existing `xsd` file? – Megrez7 Nov 27 '19 at 09:44
  • If don't know the XML, but if the _string_ differs from the one used/defined in the XML, it won't work. – zx485 Nov 27 '19 at 09:48