GravityPDF / querypath

A fork of QueryPath: a PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP8.3 support
Other
21 stars 2 forks source link

Could not find the method to replace text with any outerText of element. #14

Closed jakejackson1 closed 1 year ago

jakejackson1 commented 1 year ago

From querypath created by imsaeedafzal: technosophos/querypath#158

I could not find the method to replace text with outerText of any element. For example, I want to replace Div A source with Div B.

Div A:

Hello World

Div B:

Hello QueryPath

Expected Out:

Hello World

Can you please help me on it that how I can replace outertext? It's really creating a lot problem for me.

Thanks in advance!

jakejackson1 commented 1 year ago

Hi. Any response?

jakejackson1 commented 1 year ago

Sorry, I started to write a comment and then never finished.

Can you give me some markup so that I can understand better? I am guessing that what you are asking for may be a multi-step process with the current QueryPath. Something like qp('div.a')->text(qp('div.b')->text())

jakejackson1 commented 1 year ago

Hi Matt,

Your time is always valuable for me. Infect, I have been already waiting a lot for your answer since that day, now good to see your answer on it. Really thanks for doing this. :) :+1:

Well, actually I'm trying to read or write the outer HTML text of element.

Suppose I have this code like: <div> <div>Hello World</div> </div>

If I use innerHtml() method. It will return me this code <div>Hello World</div>.

But when I try get outerHtml by using this method outerHtml(). It should return complete html to me like this <div> <div>Hello World</div> </div>. But unfortunately I could not find way to get outerHtml of any element in QP.

More, I also want to replace the outer text of any element.

Element A) <div> <div> Hello World </div> </div>

I want this Output) <section> <div> Hello World </div> </section>

Can you please help me on it?

Thanks for your time again.

jakejackson1 commented 1 year ago

@cognifloyd Thanks for helping me. Sure. let me correct it and send back again.

jakejackson1 commented 1 year ago

@sirsmac you're html markup didn't come through. Try editing your post and putting it in three backticks:

put your example between the triple backticks

See https://guides.github.com/features/mastering-markdown/#examples for more on how to format your posts including several examples on how to format code.

jakejackson1 commented 1 year ago

Ah, yes... this is something that would be very nice to do easily. Right now, the "best" way is to...

  1. find the part you want to move
  2. append the new wrapper after it
  3. remove the part you want to move
  4. then append the removed part inside of the wrapper

That's a huge pain. If anyone feels like writing a method to do that, I'd certainly merge that pull request.

jakejackson1 commented 1 year ago

@technosophos I have fixed the html markup problem. Please check. @cognifloyd Thanks for helping me. Next time I will do it in same way.