@mc , Based on my test, you could try the following code to get identifier from metadata node.
private void button1_Click(object sender, EventArgs e)
{
string path = "D:\\test.xml";
XNamespace xn1 = "http://www.idpf.org/2007/opf";
XDocument doc = XDocument.Load(path);
XNamespace xn2 = "http://purl.org/dc/elements/1.1/";
var result = doc.Descendants(xn1 + "metadata");
foreach (var item in result.Descendants(xn2+ "identifier"))
{
textBox1.Text = item.Value;
textBox2.Text = item.Attribute("id").Value;
//Console.WriteLine(item.Value);
//Console.WriteLine(item.Attribute("id").Value);
}
}
Also, I think another method will be simpler if we don't consider that we need to get identifier from metadata node.
private void button1_Click(object sender, EventArgs e)
{
string path = "D:\\test.xml";
XDocument doc = XDocument.Load(path);
XNamespace xn2 = "http://purl.org/dc/elements/1.1/";
var item= doc.Descendants(xn2 + "identifier").FirstOrDefault();
textBox1.Text = item.Value;
textBox2.Text = item.Attribute("id").Value;
}
The both methods can get the following result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.