classic asp htmlfile object remove child

好久不见. 提交于 2019-12-11 13:28:44

问题


have to extract some info from an HTML File and strip out a div and I need to use classic asp.

I'm using HTMLFile object and it works everything except when I try to remove the div

here the relevant part of the routine:

.......

Set HTML = CreateObject("HTMLFile")
Set Frame = CreateObject("HTMLFile")  

.........  

tmp=t.ReadAll
HTML.Write tmp
t.close

Set SPN=HTML.getElementsByTagName("div")
for each sp in SPN
    if sp.getAttribute("id")="frame" then
        Frame.write sp.InnerHTML
        exit for
    end if
next        

Set Divs=Frame.getElementsByTagName("div")
for each div in Divs
    if div.getAttribute("id")="link_1" then
        Frame.removeChild(div)
    end if
next

it returns

htmlfile error '80070057'
Invalid argument
Line 57

Where command is Frame.Removechild(div)

can suggest solution or a link where can find documentation about HTMLFile Object.. since I googled a lot but apparently with wrong keywords

Thanks

Joe


回答1:


I think that the Docs for HTMLFILE start here.

According to the docs for removeChild, the incantation needed to remove node X is:

X.parentNode.removeChild X

If you change the delete demo code from here

oDOM.childNodes(0).childNodes(1).removeChild DOM.childNodes(0).childNodes(1).childNodes(0)

to

  Set p = oDOM.getElementsByTagName("P")(0)
  p.parentNode.removeChild p
  WScript.Echo "After deleting first P"
  dumpDoc oDOM

you should get

...

-----------------
After changing second P's .innerTEXT to "pipapo"
 oDOM.documentElement: HTML
 oDOM.childNodes.length 1
   1 HTML "<HEAD></HEAD><BODY><P>G</P><P>pipapo</P></BODY>"
    1 HEAD ""
     1 TITLE ""
    1 BODY "<P>G</P><P>pipapo</P>"
     1 P "G"
      3 #text "G"
     1 P "pipapo"
      3 #text "pipapo"
-----------------
After deleting first P
 oDOM.documentElement: HTML
 oDOM.childNodes.length 1
   1 HTML "<HEAD></HEAD><BODY><P>pipapo</P></BODY>"
    1 HEAD ""
     1 TITLE ""
    1 BODY "<P>pipapo</P>"
     1 P "pipapo"
      3 #text "pipapo"
-----------------
...


来源:https://stackoverflow.com/questions/37086814/classic-asp-htmlfile-object-remove-child

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!