Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

XMLDocument not load a xml url

(0) ShareShare
ReportReport
Posted on by 1,867

Hi

i have this job and when I execute job  for fist url all is ok but for the second system can read nothing.

static void TEST(Args _args)
{

XmlDocument xmlRates;
XmlNode currencyNode;

str url = "https://www.ecb.europa.eu/.../eurofxref-daily.xml";
str url2 = "https://www.bnr.ro/nbrfxrates.xml";


System.Exception ex;

Set permissionSet;
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(url, 'r'));

CodeAccessPermission::assertMultiple(permissionSet);

xmlRates = new XmlDocument();

xmlRates.load(url);

CodeAccessPermission::revertAssert();

permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(url2, 'r'));

CodeAccessPermission::assertMultiple(permissionSet);

xmlRates = new XmlDocument();

xmlRates.load(url2);

CodeAccessPermission::revertAssert();
}

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: XMLDocument not load a xml url

    Also, when sharing your code, please click "Use rich text formatting" - "Insert" - "Code" so that it's easier to read.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: XMLDocument not load a xml url

    Now I tried your code again and I get an error because the object is indeed null (seems you updated your code after I last tested it). But it comes already with the first URL. In your original message you said that it works ok for the first URL but not for the second?

    Perhaps your code doesn't work at all, which would be a very different problem than having it work ok with one URL and not another.

  • Martin Dráb Profile Picture
    Martin Dráb 230,540 Most Valuable Professional on at
    RE: XMLDocument not load a xml url

    It would help if you told us which variable is null and where.

  • XB Profile Picture
    XB 1,867 on at
    RE: XMLDocument not load a xml url

    There is no errors because object is null and I can access via browser.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: XMLDocument not load a xml url

    I don't get any error. Which line of code throws the error for you?

    Can you access both URLs via browser from your dev system?

  • XB Profile Picture
    XB 1,867 on at
    RE: XMLDocument not load a xml url

    I don't get any error basically the object is null anyway this code worked a few weeks ago.

    If I tried to read some node i get a exception object is null

    static void TEST(Args _args)
    {

    XmlDocument xmlRates;
    XmlNode currencyNode;

    str url = "">www.ecb.europa.eu/.../eurofxref-daily.xml";
    str url2 = "">www.bnr.ro/nbrfxrates.xml";

    System.Net.WebClient webClient = new System.Net.WebClient();

    System.Exception ex;

    Set permissionSet;
    permissionSet = new Set(Types::Class);
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    permissionSet.add(new FileIOPermission(url, 'r'));

    CodeAccessPermission::assertMultiple(permissionSet);

    try
    {
    xmlRates = new XmlDocument();

    if(!xmlRates.load(url))
    {
    throw error("Error");
    //return;
    }

    CodeAccessPermission::revertAssert();


    permissionSet = new Set(Types::Class);
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    permissionSet.add(new FileIOPermission(url2, 'r'));

    CodeAccessPermission::assertMultiple(permissionSet);

    xmlRates = new XmlDocument();
    xmlRates.load(url2);
    /*if(!xmlRates.load(url2))
    {
    throw error("Error");
    }*/

    currencyNode = xmlRates.root();
    if (!currencyNode)
    {
    return;
    }

    }
    catch (Exception::CLRError)
    {
    ex = ClrInterop::getLastException();
    if (ex != null)
    {
    info(ex.get_Message());
    ex = ex.get_InnerException();
    if (ex != null)
    error(ex.ToString());
    }
    }
    catch (Exception::Internal)
    {
    ex = ClrInterop::getLastException();
    if (ex != null)
    info(ex.get_Message());
    }

    CodeAccessPermission::revertAssert();


    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,540 Most Valuable Professional on at
    RE: XMLDocument not load a xml url

    Make sure you catch Exception::CLRError and shows the error message, otherwise you won't get any information that an exception was thrown.

    By the way, let me change the category of this thread from Other to Development.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: XMLDocument not load a xml url

    What do you mean by "system can read nothing"? Do you get some error? I don't get any errors.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,861 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans