File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33using AngleSharp . Html . Parser ;
44using NUnit . Framework ;
55using System . Threading . Tasks ;
6+ using System . Xml . XPath ;
67using AngleSharp . Dom ;
78
89namespace AngleSharp . XPath . Tests
@@ -146,5 +147,31 @@ public void TestNameXPathFunctionOnHTMLDoc()
146147 // Assert
147148 Assert . AreEqual ( TagNames . Html , htmlNav . Evaluate ( "name()" ) ) ;
148149 }
150+
151+ [ Test ]
152+ public void MoveToParent_CallWhenCurrentNodeIsAttr_ShouldBeMovedToAttrOwnerElement ( )
153+ {
154+ // Arrange
155+ var xml = @"<root att1='value 1' att2='value 2'><child>foo</child></root>" ;
156+ var parser = new XmlParser ( ) ;
157+ var doc = parser . ParseDocument ( xml ) ;
158+ var nav = doc . CreateNavigator ( false ) ;
159+ nav . MoveToChild ( "root" , "" ) ;
160+
161+ // Act
162+
163+ if ( nav . MoveToFirstAttribute ( ) )
164+ {
165+ do
166+ {
167+ Assert . AreEqual ( nav . NodeType , XPathNodeType . Attribute ) ;
168+ }
169+ while ( nav . MoveToNextAttribute ( ) ) ;
170+ nav . MoveToParent ( ) ;
171+ }
172+
173+ // Assert
174+ Assert . AreEqual ( nav . Name , "root" ) ;
175+ }
149176 }
150177}
Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk" >
22 <PropertyGroup >
3- <Version >2.0.0-alpha-2 </Version >
3+ <Version >2.0.0-alpha-3 </Version >
44 <AssemblyVersion >2.0.0</AssemblyVersion >
5- <FileVersion >2.0.0-alpha-2 </FileVersion >
5+ <FileVersion >2.0.0-alpha-3 </FileVersion >
66 <Authors >Denis Ivanov</Authors >
77 <PackageId >AngleSharp.XPath</PackageId >
88 <AssemblyName >AngleSharp.XPath</AssemblyName >
Original file line number Diff line number Diff line change @@ -293,11 +293,16 @@ public override bool MoveToNextAttribute()
293293 return false ;
294294 }
295295
296+ if ( attr . OwnerElement == null )
297+ {
298+ return false ;
299+ }
300+
296301 var attrIndex = attr . OwnerElement . Attributes . Index ( attr ) ;
297302
298303 if ( attrIndex >= CurrentElement . Attributes . Length - 1 )
299304 {
300- return false ;
305+ return false ;
301306 }
302307
303308 _currentNode = attr . OwnerElement . Attributes [ attrIndex + 1 ] ;
@@ -313,6 +318,12 @@ public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope)
313318 /// <inheritdoc />
314319 public override bool MoveToParent ( )
315320 {
321+ if ( CurrentNode is IAttr attr )
322+ {
323+ _currentNode = attr . OwnerElement ;
324+ return true ;
325+ }
326+
316327 if ( _currentNode . Parent == null )
317328 {
318329 return false ;
You can’t perform that action at this time.
0 commit comments