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

Open XML file and list records

New Here ,
Nov 06, 2017 Nov 06, 2017

I would like to know if it is possible to use an XML file containing multiple book records so that I could create a window listing all these records for the user to choose. I've tried using the manuals but they seem to me that they are meant for other features, and I'm not sure it's possible to do what I need.

Thanks

TOPICS
Scripting
324
Translate
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

correct answers 1 Correct answer

People's Champ , Nov 07, 2017 Nov 07, 2017

Given that you have the following xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<books>
   
<book name="Book 1"/>
   
<book name="Book 2"/>
   
<book name="Book 3"/>
   
<book name="Book 4"/>
</books>

Then you can have

var main = function() {

var m = $.os[0]=="M",

wF = "XML Files : *.xml",

mF = function(f){return (f instanceof Folder ) || /\.xml$/.test(f.name)},

filter = m? mF : wF,

f = File.openDialog ("Please select xml file", filter),

books, nBook, arr = [], n = 0, i = 0;

if ( !f ) return;

f.en

...
Translate
People's Champ ,
Nov 07, 2017 Nov 07, 2017
LATEST

Given that you have the following xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<books>
   
<book name="Book 1"/>
   
<book name="Book 2"/>
   
<book name="Book 3"/>
   
<book name="Book 4"/>
</books>

Then you can have

var main = function() {

var m = $.os[0]=="M",

wF = "XML Files : *.xml",

mF = function(f){return (f instanceof Folder ) || /\.xml$/.test(f.name)},

filter = m? mF : wF,

f = File.openDialog ("Please select xml file", filter),

books, nBook, arr = [], n = 0, i = 0;

if ( !f ) return;

f.encoding ="UTF-8";

f.open('r');

x = XML( f.read() );

f.close();

books = x..book;

n = books.length();

if ( !n ) return;

while ( i<n ) {

nBook = books;

arr.push ( String( nBook.@name ) );

i++;

}

openWindow ( arr );

}

var openWindow = function(arr) {

var w = new Window('dialog'),

ls = w.add('listbox', undefined, arr),

btn = w.add('button', undefined, 'Cancel');

w.show();

};

var u;

main()

And see the result

Capture d’écran 2017-11-07 à 11.24.18.png

Translate
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