• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bulk convertion of xrefs to text

Explorer ,
Aug 09, 2018 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

219

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
community guidelines
Explorer ,
Aug 14, 2018 Aug 14, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

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
community guidelines