Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
how to modify the text of a tag, without changing it's children ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bs4user  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 8:24 pm
From: bs4user <srehtva...@gmail.com>
Date: Tue, 10 Jul 2012 17:24:25 -0700 (PDT)
Local: Tues, Jul 10 2012 8:24 pm
Subject: how to modify the text of a tag, without changing it's children ?

If a tag contains children, how can I change the text of the tag without
changing or destroying the children?

e.g., in a case like:

<*tag1*> foo <*tag2*> abcdef <*tag3*> ghijkl </*tag3*></*tag2*></*tag1*>

how can I change "foo" to "bar" without changing anything else?

I cannot simply do:
     tag1.string = "bar"
because, according to the BS4 documentation "Be careful: if the tag
contained other tags, they and all their contents will be destroyed."


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron DeVore  
View profile  
 More options Jul 10 2012, 9:59 pm
From: Aaron DeVore <aaron.dev...@gmail.com>
Date: Tue, 10 Jul 2012 18:59:35 -0700
Local: Tues, Jul 10 2012 9:59 pm
Subject: Re: how to modify the text of a tag, without changing it's children ?
Just replace the first node with the desired text:

tag.contents[0].replaceWith("new string")

Add in checks for an empty tag.contents if necessary.

-Aaron DeVore


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »