Hello everyone. I have an XML file and I need to add an attribute to an element at runtime. I have been trying to do it for a long time but its not working. Someone please help. This is part of my XML
<?xml version="1.0" encoding="utf-8"?>
<manifest identifier="SingleCourseManifest644" version="1.0" xmlns="
http://www.imsglobal.org/xsd/imscp_v1p1">
<metadata xmlns:adlcp="
http://www.adlnet.org/xsd/adlcp_v1p3">
<schema>ADL SCORM</schema>
<schemaversion>CAM 1.3</schemaversion>
</metadata>
<organizations>
<organization
identifier="Course644" structure="hierarchical">
<title>Introduction to KMx</title>
<item identifier="Course_Part213" isvisible="true">
<title>Compaq iPAQ Pocket PC</title>
.........
In the organizations element(bold) I need to add an attribute called default and it should have the value Course644 which is the value of the attribute identifier in the organization element. I am using this code to get the value of the identifier attribute
Dim
value
As String =
String.Empty
Dim reader As New XmlNodeReader(NewSCORMManifest)
While reader.Read
Select Case reader.NodeType
Case XmlNodeType.Element
If reader.Name = "organization" Then
value = reader.GetAttribute("identifier")
End If
End Select
End While
This code is working but I cannot add the attribute. I tried using setAttribute() but it gives me an error. This is the code I was trying
Dim root As XmlElement = NewSCORMManifest.DocumentElement.SelectSingleNode("/organizations")
root.SetAttribute("default", value)
And I get the error System.NullReferenceException: Object reference not set to an instance of an object. on this line root.SetAttribute("default", value)
Please help. Thank you.
Dog and wife missing. Reward for Dog.