0

I am trying to remove the second part of this string (the second block)

<resourceDescriptor name="report_mongodb_new_basic" wsType="reportUnit"  uriString="/reports/samples/report_mongodb_new_basic" isNew="false">
<label><![CDATA[report mongodb new basic]]></label>
<description><![CDATA[test 3]]></description>
<creationDate>1330693884348</creationDate>
<resourceProperty name="PROP_RESOURCE_TYPE">
    <value><![CDATA[com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit]]></value>
</resourceProperty>
<resourceProperty name="PROP_PARENT_FOLDER">
    <value><![CDATA[/reports/samples]]></value>
</resourceProperty>
<resourceProperty name="PROP_VERSION">
    <value><![CDATA[0]]></value>
</resourceProperty>
<resourceProperty name="PROP_RU_ALWAYS_PROPMT_CONTROLS">
    <value><![CDATA[false]]></value>
</resourceProperty>
<resourceProperty name="PROP_RU_CONTROLS_LAYOUT">
    <value><![CDATA[1]]></value>
</resourceProperty>
<resourceProperty name="PROP_RU_REPORT_RENDERING_VIEW">
    <value><![CDATA[]]></value>
</resourceProperty>
<resourceDescriptor wsType="datasource" isNew="false">
    <resourceProperty name="PROP_REFERENCE_URI">
        <value><![CDATA[/datasources/MongoDB]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_IS_REFERENCE">
        <value><![CDATA[true]]></value>
    </resourceProperty>

<resourceDescriptor name="report_mongodb_new_basic_" wsType="jrxml" uriString="/reports/samples/report_mongodb_new_basic_files/report_mongodb_new_basic_" isNew="false">
    <label><![CDATA[report mongodb new basic]]></label>
    <creationDate>1330693884348</creationDate>
    <resourceProperty name="PROP_RESOURCE_TYPE">
        <value><![CDATA[com.jaspersoft.jasperserver.api.metadata.common.domain.FileResource]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_PARENT_FOLDER">
        <value><![CDATA[/reports/samples/report_mongodb_new_basic_files]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_VERSION">
        <value><![CDATA[0]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_IS_REFERENCE">
        <value><![CDATA[false]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_HAS_DATA">
        <value><![CDATA[true]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_ATTACHMENT_ID">
        <value><![CDATA[attachment]]></value>
    </resourceProperty>
    <resourceProperty name="PROP_RU_IS_MAIN_REPORT">
        <value><![CDATA[true]]></value>
    </resourceProperty>
</resourceDescriptor>

I want only the first block ( From : <resourceDescriptor to </resourceDescriptor> I am currently doing this but it's not working :

var sbody = a.body; //sbody is a String
sbody.split("</resourceDescriptor>").pop();
console.log(sbody);

The result change nothing (COnsole.log is nodejs it's a print) OR

sbody.substring(sbody.indexOf("<resourceDescriptor>") + 1, sbody.indexOf("</resourceDescriptor>"));
console.log(sbody);

The result change also nothing, why ?

Thanks

3 Answers 3

1

pop returns the popped value it does not alter the object/array its called against;

var result = sbody.split("</resourceDescriptor>").pop();
console.log(result);
Sign up to request clarification or add additional context in comments.

2 Comments

THanks ! , FYI actually pop doesn't work but substring yes I have the first block but not the last part of it (</resourceDescriptor> )
This is working (but ugly) : var nbody =sbody.substring(sbody.indexOf("<resourceDescriptor>") + 1, sbody.indexOf("</resourceDescriptor>")+21);
1

This will gives you string buffer except end resourceDescriptor

sbody.split("</resourceDescriptor>")[0];
console.log(sbody);

1 Comment

actually you need a new var like Alex K said, your method work but I need the "</resourceDescriptor>" at the end
0

Alternative solution is: add the above XML inside the hidden div in your DOM, then you can access it using getElementByTagName or jQuery methods.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.