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

EvaluateXPathsForElement does not giving the xml elements in the right order as in the xml structure

Enthusiast ,
Dec 21, 2016 Dec 21, 2016

Hi All,

EvaluateXPathsForElement does not giving the xml elements in the right order as in the xml structure.

Is there anyother way to get xml elements as in the xml structure order using xpath?

Regards,

Chinna

TOPICS
SDK
1.1K
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
Enthusiast ,
Feb 03, 2017 Feb 03, 2017

Any help?

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
Enthusiast ,
Feb 03, 2017 Feb 03, 2017

Any help plz?

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
Mentor ,
Feb 04, 2017 Feb 04, 2017

Haven't used them from the plugin side, but XML rules could be an alternative. At least with CS4 scripting there were subtle differences between the older (CS3) XML rules and the later (CS4) addition of EvaluateXPaths.

For a quick scripted test, see my old simpleXMLRule.jsx script.

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
Enthusiast ,
Feb 06, 2017 Feb 06, 2017

Hi Dirk,

Sorry for the late reply. And many thanks for your reply.

Is it possible to return xml elements from script using IScriptRunner? I'm trying with the below code but I'm unable to get the result.

WideString path("F:/script/Test.jsx");

  IDFile scriptFile(path);

InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));
InterfacePtr<IScriptEngine> scriptEngine(scriptManager->QueryDefaultEngine());
InterfacePtr<IScriptRunner>scriptRunner(Utils<IScriptUtils>()->QueryScriptRunner(scriptFile));

PMString theReturnString;
PMString theErrorString;

ScriptRecordData args;
ScriptData sScript(scriptFile);
ScriptData sResultData;
Utils<IScriptArgs>()->Save();
Utils<IScriptArgs>()->Set("xpath","//qlink[@ref-type]");
ErrorCode status = Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner, sScript, args, sResultData, theErrorString, kFalse);

Regards,

Chinna

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
Mentor ,
Feb 07, 2017 Feb 07, 2017

I did not mean to use a script for production code, just try your trouble xpath expression and test document to see whether the xml rule approach makes any difference at all. Only if it looks promising we should then try to get the rules processor running from the plugin side, not call it thru scripting.

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
Enthusiast ,
Feb 07, 2017 Feb 07, 2017

Hi Dirk,

Thanks for your reply.

Yes xml rule makes difference. It returns the xml elements as in the xml structure from top to bottom. But evaluateXPathExpression returns the xml elements as last-in last order.

Here is the code I'm trying now. It returns the last inserted elements in the structure as first and so on.

IDocument *doc = Utils<ILayoutUIUtils>()->GetFrontDocument();

UIDRef docref = ::GetUIDRef(doc);

IDataBase *db = docref.GetDataBase();

K2Vector<WideString> xPaths;

xPaths.push_back(WideString("//qlink[@ref-type]"));

InterfacePtr<IIDXMLElement> rootElement(Utils<IXMLUtils>()->QueryRootElement(db));

XMLReference root(Utils<IXMLUtils>()->GetImportedRootXMLReference(doc));

HitMatches matches;

Utils<IXMLParserUtils>()->EvaluateXPathsForElement(xPaths, rootElement, matches, 0);

std::map<XMLReference, K2Vector<int32>>::reverse_iterator iterator = matches.rbegin();

std::map<XMLReference, K2Vector<int32>>::reverse_iterator iterator_end = matches.rend();

while(iterator != iterator_end)

{

    WideString wstr;

    XMLReference xmlref = iterator->first;

    InterfacePtr<IIDXMLElement> element(xmlref.Instantiate());

    XMLContentIterator iter(element->begin());

    for(; iter != element->end(); iter++)

    {

        InDesign::TextRange range = *iter;

        if(range.Length()>0)

        {

            do

            {

                InterfacePtr<ITextModel> textModel(range.QueryModel());

                TextIterator begin(textModel, range.Start());

                TextIterator end(textModel, range.End());

                for (TextIterator iterr = begin; iterr != end; iterr++)

                {

                    const UTF32TextChar characterCode = *iterr;

                    wstr.Append(characterCode);

                }

            }

            while(false);

        }

    }

    for(int i=0;i<element->GetChildCount();i++)

    {

        XMLReference childRef = element->GetNthChild(i);

        InterfacePtr<IIDXMLElement> childelement(childRef.Instantiate());

        XMLContentIterator iter(childelement->begin());

        for(; iter != childelement->end(); iter++)

        {

            InDesign::TextRange range = *iter;

            if(range.Length()>0)

            {

                do

                {

                    InterfacePtr<ITextModel> textModel(range.QueryModel());

                    TextIterator begin(textModel, range.Start());

                    TextIterator end(textModel, range.End());

                    for (TextIterator iterr = begin; iterr != end; iterr++)

                    {

                        const UTF32TextChar characterCode = *iterr;

                        wstr.Append(characterCode);

                    }

                }

                while(false);

            }

        }

    }

    PMString str(wstr);

    CAlert::InformationAlert(str);

    iterator++;

}

Regards,

Chinna

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
Explorer ,
Feb 07, 2017 Feb 07, 2017
LATEST

Maybe there's a problem with iterators direction?

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