2
Reply

want to change xml attribute name.

Karthi Keyan

Karthi Keyan

Apr 6 2017 2:13 AM
221
Hi, I am having an xml file. I want to change the attribute name of one node. 
 
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//NLM//DTD Book DTD v2.3 20070202//EN" "book.dtd">
<book xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="2.3">
<book-meta>
<book-id pub-id-type="doi">10.1163/9789004318168</book-id>
<book-title-group>
<book-title>Lay Prophets in Lutheran Europe (<italic>c</italic>. 1550–1700)</book-title>
</book-title-group>
<volume>74</volume>
<series>Brill’s Series in Church History and Religious Culture</series>
<contrib-group>
<contrib contrib-type="author">
<name>
<surname>Beyer</surname>
<given-names>Jürgen</given-names>
</name>
</contrib>
</contrib-group>
<publisher>
<publisher-name>Brill</publisher-name>
<publisher-loc>Leiden</publisher-loc>
</publisher>
<isbn>9789004156289</isbn>
<isbn content-type="e-ISBN">9789004318168</isbn>
<pub-date pub-type="epub"><year>2017</year></pub-date>
<permissions>
<copyright-statement>Copyright 2017 by Koninklijke Brill NV, Leiden, The Netherlands</copyright-statement>
<copyright-year>2017</copyright-year>
<copyright-holder>Koninklijke Brill NV incorporates the imprints Brill, Brill Hes &amp; De Graaf, Brill Nijhoff, Brill Rodopi and Hotei Publishing.</copyright-holder>
</permissions>
</book-meta>
 </book>
 
 
in this i want to change the  pub-id-type into book-id-type. i tried with following code. but i always got null error. what is the problem in that.
 
doc.XPathSelectElement("//book-meta/book-id").Attribute("pub-id-type").Remove();
doc.XPathSelectElement("//book-meta/book-id").SetAttributeValue("book-id-type", "doi");
 
 
Thanks in advance. 
 

Answers (2)