Hello,
Id like to read in a XML file elements content into a number of arrays
(if it makes any difference: Im using PL-SQL associative arrays to make
a "bulk" insert of the XML file into an Oracle table)
Since spread6m element is not present in each of the root elements (see the attachment for a screenshoot), application throws "Object reference not set to an instance of an object."
Ive tried something similar too
but it did not really seem to help
So the question is: how can I detect that an element is missing within the current root element and populate the arrays item with 0 accordingly?
Thanks,
Shurik.
Id like to read in a XML file elements content into a number of arrays
(if it makes any difference: Im using PL-SQL associative arrays to make
a "bulk" insert of the XML file into an Oracle table)
Code:
//"load" the xml file
XmlTextReader textReader = New XmlTextReader(path);
textReader.Read();
XmlDocument doc = New XmlDocument();
doc.Load(textReader);
// Get all elements here
XmlNodeList gridid = doc.GetElementsByTagName("gridid");
XmlNodeList spread6m = doc.GetElementsByTagName("Spread6m");
.... other elements go here
// Loop throught the whole document And populate the arrays (declared And instantiated alerady)
For (int i = 0; i < CountElements; i++)
{
GridIDArray[i] = System.Convert.ToInt32(gridid[i].InnerXml);
Spread6mArray[i] = System.Convert.ToString(spread6m[i].InnerXml);
}
...
Since spread6m element is not present in each of the root elements (see the attachment for a screenshoot), application throws "Object reference not set to an instance of an object."
Ive tried something similar too
Code:
// Get a XML node Type object.
Type XmlNodeType = TypeOf(XmlNode);
If (XmlNodeType.IsInstanceOfType(spread6m[i]))
{
Spread6mArray[i] = System.Convert.ToString(spread6m[i].InnerXml);
}
Else
{
Spread6mArray[i] = 0;
}
but it did not really seem to help
So the question is: how can I detect that an element is missing within the current root element and populate the arrays item with 0 accordingly?
Thanks,
Shurik.