Skip to content

[skip ci] Doc for Node#add_child#3453

Merged
flavorjones merged 9 commits intosparklemotion:mainfrom
BurdetteLamar:node_add_child_doc
Apr 5, 2025
Merged

[skip ci] Doc for Node#add_child#3453
flavorjones merged 9 commits intosparklemotion:mainfrom
BurdetteLamar:node_add_child_doc

Conversation

@BurdetteLamar
Copy link
Copy Markdown
Contributor

No description provided.

@BurdetteLamar
Copy link
Copy Markdown
Contributor Author

@flavorjones, in the event, I'm less convinced about the extended-form "Related" I've shown here. See what you think.

Copy link
Copy Markdown
Member

@flavorjones flavorjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I like this addition to the documentation. I made a few small notes.

Comment thread lib/nokogiri/xml/node.rb Outdated
# returns +object+:
#
# bookstore_doc = Nokogiri::XML::Document.parse(BOOKSTORE_XML)
# book_nodeset = bookstore_doc.search('//book')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we did not use search in examples. I've been trying to discourage the use of that method for many years. Let's please use either xpath or css.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flavorjones, going forward, do have a preference between the two?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a preference, honestly. Depending on the task, an xpath query or a css selector might be easier ... Or if we want to cater to the reader, XML examples might use XPath, and HTML examples might use CSS?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, thanks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread lib/nokogiri/xml/node.rb Outdated
# doc = Nokogiri::XML::Document.parse(xml)
# src_child_node = doc.at_css('src_child')
# dst_parent_node = doc.at_css('dst_parent')
# dst_parent_node.add_child(src_child_node)
Copy link
Copy Markdown
Member

@flavorjones flavorjones Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like these examples to also illustrate the final state of the document, after the changes were made. Maybe this could be as simple as something like this:

# doc.to_xml
# # => '<root>...</root>'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-worked.

Comment thread lib/nokogiri/xml/node.rb Outdated
# doc = Nokogiri::XML::Document.parse('<root/>')
# doc.root.add_child('<foo/><bar/>')
#
# [Related]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this doesn't feel particularly high-value. I've already got methods bucketed by general function, e.g.:

      # :section: Manipulating Document Structure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised.

Comment thread lib/nokogiri/xml/node.rb Outdated

###
# Add +node_or_tags+ as a child of this Node.
0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@BurdetteLamar
Copy link
Copy Markdown
Contributor Author

@flavorjones, I have re-worked the examples to show before/after states.

@flavorjones
Copy link
Copy Markdown
Member

@BurdetteLamar This looks great! Merging. Thank you! 🙇

@flavorjones flavorjones merged commit a024cff into sparklemotion:main Apr 5, 2025
Copy link
Copy Markdown

@Reality2byte Reality2byte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this and want to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants