Code Monkey home page Code Monkey logo

Comments (5)

zhengchun avatar zhengchun commented on June 11, 2024

How about xmlquery and htmlquery? this xpath package only works for XPath not provides DOM manipulate.

antchfx/xmlquery#38

https://pkg.go.dev/golang.org/x/net/html#Node

from xpath.

suntong avatar suntong commented on June 11, 2024

I don't quite understand what you are suggestion here. Maybe you can try explaining in Chinese? I understand that there is a similar request at antchfx/xmlquery#38, but I don't need xmlquery, but xpath. So,

Can we at least Expose the following *Node related helper functions first pls?

xpath/xpath_test.go

Lines 654 to 659 in cd2afb8

doc := createNode("", RootNode)
xhtml := doc.createChildNode("html", ElementNode)
xhtml.addAttribute("lang", "en")
// The HTML head section.
head := xhtml.createChildNode("head", ElementNode)

If there are other helper functions, like AddAttr, AddChild, AddSibling, RemoveFromTree. Would it be OK to expose them as well?

As I understand that xpath is a pure subset of xmlquery, so if xmlquery can do functions like AddAttr, AddChild, AddSibling, RemoveFromTree, then I see no reason why xpath cannot. Or, better yet, maybe letting xpath and xmlquery share the same xml node handling function is not a bad idea, since they are so similar.

from xpath.

suntong avatar suntong commented on June 11, 2024

They said that XPath 1.0 is only focus on selection, but XPath 2.0's focus has been shifted to XML manipulation. I may have not express it well, but I don't need dom manipulation, I only need functions like AddAttr, AddChild, AddSibling, RemoveFromTree, onto the given located xpath node(s).

from xpath.

zhengchun avatar zhengchun commented on June 11, 2024

Sorry for I didn't make it clear.

XPath is a document query package, it helps you easy find some matched in your document like HTML, XML, JSON and other document and don't need understand your DOM package. In htmlquery and xmlquery and jsonquery they are all implemented NodeNavigator interface, that means you can create owned DOM and supports XPATH query.

for example, you have a HTML document. when you get the returned HTML node, you can also do some other operations in your DOM package: AddAttribute, AppendChild,

for example:

node:= htmlquery.FindOne(doc,"//div")
node.AddAttribute("class","link") // in here, we assume HTML node have a AddAttribute() method.
node2:= htmlquery.FindOne(doc,"//div[@class='link']"

createChildNode and addAttribute in the xpath_test.go file are just convenient for testing.

from xpath.

suntong avatar suntong commented on June 11, 2024

Ah, make sense. thx!

from xpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.