Highlighted

Bulk convertion of xrefs to text

Explorer ,
Aug 09, 2018

Copy link to clipboard

Copied

Hi all,

we need to convert a large amount of cross references to plain text. Are you aware of a script that can do this, or do you have any recommendations? The xrefs partially reference the titles of the target chapters, but partially they also contain a manually written link text.

TOPICS
Structured

Views

117

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Bulk convertion of xrefs to text

Explorer ,
Aug 09, 2018

Copy link to clipboard

Copied

Hi all,

we need to convert a large amount of cross references to plain text. Are you aware of a script that can do this, or do you have any recommendations? The xrefs partially reference the titles of the target chapters, but partially they also contain a manually written link text.

TOPICS
Structured

Views

118

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 09, 2018 0
Explorer ,
Aug 14, 2018

Copy link to clipboard

Copied

this might work for one file you opened:

var doc = app.FirstOpenDoc;

//get the map of the xml file:

var tempxmlMap = ReadXML(doc.Name)

//gather xrefs from the map:

var xmlXRefs = tempxmlMap..xref;

//loop through the xrefs found in the map:

for( var i = 0; i < xmlXRefs.length( ); i++ ) {

    var sHref = xmlXRefs.@href.toString( );

    //PartofsHref = sHref.replace(/#.*/g, "") //use regex magic to extract the part of the xref you need

    var xrefList=new File("D:\\xref.txt");

    if(!xrefList.exists) {

                xrefList.open('w');

            } else {

                xrefList.open('a');

            }

    xrefList.writeln(doc.Name + "\trefers to:\t" + sHref); //or PartofsHref instead of sHref

    xrefList.close();

}

//function to get check validity and get the map:

function ReadXML(filename) {

    var xmlMap;

    var oFile = File(filename);

    if( oFile.open( 'r' ) ){

        sContents = oFile.read( oFile.length );

        oFile.close( );

        try {

            xmlMap = new XML( sContents );

        }

        catch(err) {

            $.writeln(filename + "\t" + err.toString().replace("\n", " "))

            return false

        }

    }

    return xmlMap;

}

you may adapt the script to make it loop through several files.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 14, 2018 0