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

Read xml file

Explorer ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

  1. <?xml version="1.0" encoding="UTF-8"?>
    <Config>
    <Journal id="TandF">
    <alt-title-icon path="D:\Anupam\RY"/>
    <toolname name="RY"/>
    <template indesign="D:\Anupam\RY\temp"/>
    </Journal>
    </config>

 

not ablr to read highlighted tag

 

var myProject = myxml.Journal;

for (var i = 0; i < myProject.length(); i++){
toolname = myProject[0].toolname .@name;
var logoPath=myProject[0].alt-title-icon.@path; ....not able to read bold part able to read toolname
}
}

TOPICS
Scripting

Views

567

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

correct answers 1 Correct answer

Explorer , Oct 11, 2021 Oct 11, 2021

Thanks all of you.

I used the below line to read the path and stored in my path.its working.

myPath=myProject[0].xpath("\\alt-title-icon").@path.toString();

 

Anupam

Votes

Translate

Translate
Guide ,
Jul 18, 2021 Jul 18, 2021

Copy link to clipboard

Copied

 myProject.xpath("//alt-title-icon/@path")

should work.

 

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
Community Expert ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Hi Dirk,

hm, yes.

 

Note: The backslashes in the path string will not be returned…

This is an issue of the data source. The backslashes are not escaped.

 

Regards,
Uwe Laubender

( ACP )

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
Guide ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Hi Uwe,

 

above was no working code example, I assume the XML was manually typed (telling from the lowercase end tag "config").

 

When you wrap it in JS / E4X to get the example going, you will lose the single backslash, because for a literal in your overall JS source you'd need them escaped. Otherwise the single backslash should be ok, nothing to worry about the data source.

 

OP chould have used the toSource() method to produce the example.

 

The issue of OP is the minus in the element names, which is not the best choice for a Javascript / E4X name.

I think instead of xpath something like myProject["da-name"] would also work, or some variation on xml node functions - e.g. element("da-name") .

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
Community Expert ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Hi Dirk,

I understand…

myProject["alt-title-icon path"]

is working. It returns "D:AnupamRY"

 

Regards,
Uwe Laubender

( ACP )

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
Engaged ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Anupam,

 

You used loop then why you used myProject[0] instead of myProject[i]?

 

Sumit

 

 

-Sumit

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
LEGEND ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Just to clarify, backslashes have no special meaning in XML, and the data in <alt-title-icon path="D:\Anupam\RY"/> is simply 

D:\Anupam\RY

Double backslashes will mean double backslashes. NOW, the app processing the data might (unusually) have additional rules for backslashes, but that isn't what I'd expect.

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
Explorer ,
Oct 11, 2021 Oct 11, 2021

Copy link to clipboard

Copied

that "i" is used  for different purpose.

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
Explorer ,
Oct 11, 2021 Oct 11, 2021

Copy link to clipboard

Copied

LATEST

that "i" is used  for different purpose.

 

Likes

 

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
Community Expert ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Hi Test Screen Name,

just tested three real-world samples for the path on my Windows 10 machine using the ESTK.

<alt-title-icon path="F:\Versionen\GehezuZiel-2021_1.indd"/>
<alt-title-icon path="F:\\Versionen\\GehezuZiel-2021_1.indd"/>
<alt-title-icon path="F:/Versionen/GehezuZiel-2021_1.indd"/>

Tested the returned path with:

File( myProject.xpath("//alt-title-icon/@path") ).exists

 

The first one returned false, the other ones returned true.

 

Regards,
Uwe Laubender

( ACP )

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
LEGEND ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

That would seem to be an oddity of the File method, or of xpath's "path" processing. It isn't an XML property.

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
Explorer ,
Oct 11, 2021 Oct 11, 2021

Copy link to clipboard

Copied

Thanks all of you.

I used the below line to read the path and stored in my path.its working.

myPath=myProject[0].xpath("\\alt-title-icon").@path.toString();

 

Anupam

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