Why do I get false value for hasIdentifier variable, when I see in i-th document anything_start_i.xml that there is <identifier>value</identifier> element.
XDocument doc = XDocument.Load(args[0] + "/?verb=GetRecord&metadataPrefix=p3dm&identifier=" + i);
doc.Save("anything_start" + i + ".xml");
bool hasIdentifier = doc.Elements("identifier").Any();
Console.WriteLine(hasIdentifier);
Tried with Descendants instead of Elements, and again false.
XML:
<?xml version="1.0" encoding="utf-8"?>
<OAI-PMH xmlns="..." xmlns:xsi="..." xsi:schemaLocation="...">
<responseDate>...</responseDate>
<request verb="GetRecord" identifier="1"</request>
<GetRecord>
<record>
<header>
<identifier>1</identifier>
<datestamp>...</datestamp>
</header>
<metadata>
<P3DM xmlns="..." xsi:schemaLocation="...">
<MODELINFOID>1</MODELINFOID>
<TITLE>Roth</TITLE>
....
Well, I would like to save all documents, and trying to stop saving when there is no documents any more (actually there is but without meaningful data). So, this is how i started:
static void Main(string[] args)
{
var i = 1;
bool work = true;
do{
XDocument doc = XDocument.Load(args[0] + "/?verb=GetRecord&metadataPrefix=p3dm&identifier=" + i);
bool hasIdentifier = doc.Elements("identifier").Any();
if (hasIdentifier) {
doc.Save("anything" + i + ".xml");
i++;
}else{
work = false;
}
} while (work);
x:breaks my searches in XML" AKA "how to use namespaces to select nodes".