cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Using ACL Script! how do i find out the number of charachters enclosed in a pair of tags

2peter
1-Newbie

Using ACL Script! how do i find out the number of charachters enclosed in a pair of tags

Hi

I want to write a script that deletes all empty tags in alarge document, ie. <ptxt></ptxt>.

How can i use ACL to identify all empty tags? are there any variables that i can use to find theese!

Kind regards Peter Jämting

3 REPLIES 3

You can use an xpath to return a node tree of the whole document, then oid_content() to check each one for content and mark for deletion.

Is this just for elements that contain no children or PCDATA when they should? Is it possible that these elements might have attributes defined?

Quick and dirty, off the top of my head...

ret=oid_xpath_nodeset(oid_root(),nodearr,"//*")
for(n in nodearr){
if(!oid_content(nodearr[n]){
oid_delete(nodearr[n])
}
}

If you want to use ACL, there is an OID function, oid_empty() that will identify EMPTY elements. Then just select (oid_select()) and delete the selection.

You can tie this in with the 'oid_content_model()' function and verify the ELEMENT itself is EMPTY (and not just a tag with no content).

Something like this

if(oid_empty(o)=="1" && oid_content_model(o)!="EMPTY")

Then use 'oid_delete()' function to delete the OID.

You'll need to run something to traverse the file,

o=oid_first()
while oid_valid(o)
{
if(oid_empty(o)=="1" && oid_content_model(o)=="EMPTY")
{oid_delete(o)}
o=oid_forward(o)
}

That is pretty close, may take some tweaking, but close enough to start.


Lynn
---- "Buss wrote:
> You can use an xpath to return a node tree of the whole document, then oid_content() to check each one for content and mark for deletion.
>
> Is this just for elements that contain no children or PCDATA when they should? Is it possible that these elements might have attributes defined?
>
> Quick and dirty, off the top of my head...
>
> ret=oid_xpath_nodeset(oid_root(),nodearr,"//*")
> for(n in nodearr){
> if(!oid_content(nodearr[n]){
> oid_delete(nodearr[n])
> }
> }
>
2peter
1-Newbie
(To:2peter)

Thanks for you help.

Kind regards Peter Jämting

Top Tags