NodeListItem Property |
Namespace: Aspose.Words
The index is zero-based.
Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.
If index is greater than or equal to the number of items in the list, this returns a null reference.
If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert some nodes with a DocumentBuilder builder.Writeln("Hello world!"); builder.StartTable(); builder.InsertCell(); builder.Write("Cell 1"); builder.InsertCell(); builder.Write("Cell 2"); builder.EndTable(); #if NETFRAMEWORK builder.InsertImage(Image.FromFile(ImageDir + "Logo.jpg")); #else using (SKBitmap image = SKBitmap.Decode(ImageDir + "Logo.jpg")) builder.InsertImage(image); #endif // Get all run nodes, of which we put 3 in the entire document NodeList nodeList = doc.SelectNodes("//Run"); Assert.AreEqual(3, nodeList.Count); // Using a double forward slash, select all Run nodes that are indirect descendants of a Table node, // which would in this case be the runs inside the two cells we inserted nodeList = doc.SelectNodes("//Table//Run"); Assert.AreEqual(2, nodeList.Count); // Single forward slashes specify direct descendant relationships, // of which we skipped quite a few by using double slashes Assert.AreEqual(doc.SelectNodes("//Table//Run"), doc.SelectNodes("//Table/Row/Cell/Paragraph/Run")); // We can access the actual nodes via a NodeList too nodeList = doc.SelectNodes("//Shape"); Assert.AreEqual(1, nodeList.Count); Shape shape = (Shape)nodeList[0]; Assert.True(shape.HasImage);