-
1. Re: Import XML... vs .importXML [JS CS4]
[Jongware] Mar 21, 2010 9:39 AM (in response to pbear*)I'm sorry to say this, but ... running that javascript on your sample XML results in this:
-- which looks suspiciously similar to your "correct" version!
Perhaps a few basic checks are in order:
* is your sample.xml saved as plain text? (I suppose it is, because ID itself can read it. Check anyway, will you?)
* are you sure the file opened in your script is the one you intended? I put the XML file in the Scripts folder, and used this for path:
myDocument.xmlElements[0].importXML(File(app.activeScript.path + "/sample.xml"));
* ... can't think of anything else ...(Ed.) My version is not showing any XML contents, but that's because it's a preference which accidentally was "off" on my system. It's still the same. -
2. Re: Import XML... vs .importXML [JS CS4]
[Jongware] Mar 21, 2010 10:22 AM (in response to [Jongware])Another possibility
Running the script doesn't "open" the XML tree in the Structures panel. If you open the Root item, it shows "persons" but not its contained items. However, since I saw the little triangle on the left, I knew there was more to it and opened that too. Perhaps ... your InDesign forgot to draw that "there-is-more" triangle!
Did you know clicking the Open triangle with the Alt button down (on a Mac) also opens all elements within? I just found that accidentally ... (Plenty surprises left, I guess.)
-
3. Re: Import XML... vs .importXML [JS CS4]
pbear* Mar 21, 2010 1:58 PM (in response to [Jongware])First off, thanks for the reply!
Perhaps a few basic checks are in order:
* is your sample.xml saved as plain text? (I suppose it is, because ID itself can read it. Check anyway, will you?)
As sample.xml or sample.txt, as UTF-8 with or without the BOM – no go.
* are you sure the file opened in your script is the one you intended? I put the XML file in the Scripts folder, and used this for path:
myDocument.xmlElements[0].importXML(File(app.activeScript.path + "/sample.xml"));
If I remove the one I think I'm using on the Desktop it gives me a modal window saying the file can't be found. I tried the above path with a copy of the XML in the same folder as the script with the same results.
* ... can't think of anything else ...
(Ed.) My version is not showing any XML contents, but that's because it's a preference which accidentally was "off" on my system. It's still the same.Running the script doesn't "open" the XML tree in the Structures panel. If you open the Root item, it shows "persons" but not its contained items. However, since I saw the little triangle on the left, I knew there was more to it and opened that too. Perhaps ... your InDesign forgot to draw that "there-is-more" triangle!
Did you know clicking the Open triangle with the Alt button down (on a Mac) also opens all elements within? I just found that accidentally ... (Plenty surprises left, I guess.)
I clicked, option-clicked, command-clicked, command-option clicked... where the disclosure triangle next to "persons" should be, and no results. Clicking the same way on "Root" only discloses "persons". (That's a cool trick for showing all items though.)
If I select "persons" and choose "New Element..." from the Structure Panel menu I get a choice of:
person
persons
RootI can't add more to the newly created "person" in the same (or any) way. Options at higher levels remain the same.
Is one of these wrong?
function setXMLPrefs(){
var myDocument = app.documents.item(0);
// XML View Preferences
var myXMLViewPreferences = myDocument.xmlViewPreferences;
myXMLViewPreferences.showAttributes = true;
myXMLViewPreferences.showStructure = true;
myXMLViewPreferences.showTaggedFrames = true;
myXMLViewPreferences.showTagMarkers = true;
myXMLViewPreferences.showTextSnippets = true;
// XML Import Prefs
var myXMLImportPreferences = myDocument.xmlImportPreferences;
myXMLImportPreferences.allowTransform = false;
myXMLImportPreferences.createLinkToXML = false;
myXMLImportPreferences.ignoreUnmatchedIncoming = true;
myXMLImportPreferences.ignoreWhitespace = true;
myXMLImportPreferences.importCALSTables = true;
myXMLImportPreferences.importStyle = XMLImportStyles.mergeImport;
myXMLImportPreferences.importTextIntoTables = false;
myXMLImportPreferences.importToSelected = false;
myXMLImportPreferences.removeUnmatchedExisting = false;
myXMLImportPreferences.repeatTextElements = true;
} -
4. Re: Import XML... vs .importXML [JS CS4]
[Jongware] Mar 21, 2010 2:46 PM (in response to pbear*)At this point, I'm happy to leave it to XML experts ...
All I did was copying your XML into a new file and running the two-line script to import it. It seems one of the settings you set in the full script makes it go goo-goo. Perhaps you could remove one line at a time until it works ... (a.k.a. "debugging by exclusion" )
-
5. Re: Import XML... vs .importXML [JS CS4]
pbear* Mar 21, 2010 3:24 PM (in response to [Jongware])It seems one of the settings you set in the full script makes it go goo-goo. Perhaps you could remove one line at a time until it works ... (a.k.a. "debugging by exclusion" )
Now we're cookin'...
myXMLImportPreferences.ignoreUnmatchedIncoming = false; // if true, no XML for you!
The only thing I don't like is this adds an additional layer of xmlElements[0] to an already tedious path. I thought I read something about E4X with InDesign...
var monthOfBirth = persons.person.date.month;
would be nice. I guess XML for InDesign is geared towards other sensibilities.
-
6. Re: Import XML... vs .importXML [JS CS4]
[Jongware] Mar 21, 2010 4:32 PM (in response to pbear*)Odd.
"If true, ignores elements that do not match the existing structure. Note: Valid only when import style is merge." (from the JS help; my emphasis).
It must be some oddity, because I understand why you would use this when updating some data (you wouldn't want a host of new elements pop up), but what's with that note?
The only thing I don't like is this adds an additional layer of xmlElements[0]
You mean, you're getting your data below the initially existing "Root"? If you rename that to "persons" before running the two-line script (the one that runs without problems ), ID will understand what you were intending to do and add the "person" data immediately below it.
-
7. Re: Import XML... vs .importXML [JS CS4]
pbear* Mar 21, 2010 6:30 PM (in response to [Jongware])Your posted example also has Root > persons > ...
I'll give renaming "Root" a try as "persons" from the import is really the root of the file.
Thanks for the help!
-
8. Re: Import XML... vs .importXML [JS CS4]
[Jongware] Mar 21, 2010 7:40 PM (in response to pbear*)Your posted example also has Root > persons > ...
Yes, I was just wondering what would happen if ... Turns out I was right!




