1//
2// ChildNodesList.cpp
3//
4// Library: XML
5// Package: DOM
6// Module: DOM
7//
8// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/DOM/ChildNodesList.h"
16#include "Poco/DOM/Node.h"
17#include "Poco/DOM/Document.h"
18
19
20namespace Poco {
21namespace XML {
22
23
24ChildNodesList::ChildNodesList(const Node* pParent):
25 _pParent(pParent)
26{
27 poco_check_ptr (pParent);
28
29 _pParent->duplicate();
30}
31
32
33ChildNodesList::~ChildNodesList()
34{
35 _pParent->release();
36}
37
38
39Node* ChildNodesList::item(unsigned long index) const
40{
41 unsigned long n = 0;
42 Node* pCur = _pParent->firstChild();
43 while (pCur && n++ < index)
44 {
45 pCur = pCur->nextSibling();
46 }
47 return pCur;
48}
49
50
51unsigned long ChildNodesList::length() const
52{
53 unsigned long n = 0;
54 Node* pCur = _pParent->firstChild();
55 while (pCur)
56 {
57 ++n;
58 pCur = pCur->nextSibling();
59 }
60 return n;
61}
62
63
64void ChildNodesList::autoRelease()
65{
66 _pParent->ownerDocument()->autoReleasePool().add(this);
67}
68
69
70} } // namespace Poco::XML
71