0

Following is the XML format:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en">
<head>
<meta name="dtb:uid" content="0000000000000"/>
<meta name="dtb:depth" content="1"/>
<meta name="dtb:totalPageCount" content="pageNumber"/>
<meta name="dtb:maxPageNumber" content="0"/>
</head>
</ncx>

I need to change the value of xml:lang but I don't know how to do it.

My C# Code:

xtabdoc.Root.Descendants().FirstOrDefault(el =>(string)el.Attribute(XNamespace.Xml + "lang") == "en");

It showed null.

Please help.

2 Answers 2

1

You can get the Element by using following.

var result = XDocument.Parse(xmlString).Descendants().FirstOrDefault(el =>(string)el.Attribute(XNamespace.Xml + "lang") == "en");

The key lies in fact that Element lies in the Root. So when you use Root.Descendants, you are not considering the Node, which is why you got null.

Sign up to request clarification or add additional context in comments.

Comments

0

Easy :

           XDocument doc = XDocument.Load(FILENAME);
            XElement root = doc.Root;
            XAttribute lang = root.Attributes().Where(x => x.Name.LocalName == "lang").FirstOrDefault();
            lang.SetValue("abc");

Comments

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.