web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

XML import

(0) ShareShare
ReportReport
Posted on by 35

 Hi

 I have a working import code in Ax 2009 that imports most of my XML files fine, but the selectSingleNode fails when there is a xmlns tag in the file (see below). I can parse the file and remove that tag before I load the XML document, but is there a better way to do this?

 Here is a part of my code:

    XMLDocument     doc;
    XMLNode         rootNode,node;
    XMLParseError   xmlError;
    XMLNodeList     nodeList;
    int i;

    doc = new XMLDocument();
    //doc.async(FALSE); // is this important?
    doc.load(@"M:\ImportExport\Import\test.xml");

    // Verify Document Structure
    xmlError  = doc.parseError();

    if(xmlError && xmlError.errorCode() != 0)
    {
        throw error(strFmt("Error: %1",xmlError.reason()));
    }

    // Parsing document contents
    rootNode = doc.documentElement();

    singleNode = rootNode.selectSingleNode('PayrollProductionsChains'); // will only return a singlenode when I remove 'xmlns=...'
    if(singleNode && xml2int(singleNode.selectSingleNode('PayrollProductionsChainID')))
    {

        ...


   }

First part of XML file that the code works with:

  <?xml version="1.0" standalone="yes" ?>
- <PayrollDataSet>
- <PayrollProductionsChains>
  <PayrollProductionsChainID>1</PayrollProductionsChainID>
  <ChainID>1</ChainID>
 

First part of XML file that makes the import code fail:
<?xml version="1.0" standalone="yes" ?>
- <PayrollDataSet xmlns="http://tempuri.org/PayrollDataSet.xsd">
- <PayrollProductionsChains>
  <PayrollProductionsChainID>1</PayrollProductionsChainID>
  <ChainID>1</ChainID>
 

Regards
Inge M. Berglund

*This post is locked for comments

I have the same question (0)
  • Alex Prodan Profile Picture
    on at

    You can try using XmlNamespaceManager class:

    nmgr = new XmlNamespaceManager(new XmlNameTable());
    nmgr.addNamespace('ns', 'http://tempuri.org/PayrollDataSet.xsd');

    singleNode = rootNode.selectSingleNode('ns:PayrollProductionsChains', nmgr);

    works on this xml:

    <?xml version="1.0" standalone="yes" ?>

    <PayrollDataSet xmlns="http://tempuri.org/PayrollDataSet.xsd">

    <PayrollProductionsChains>

    <PayrollProductionsChainID>1</PayrollProductionsChainID>

    <ChainID>1</ChainID>

    </PayrollProductionsChains>

    </PayrollDataSet>

  • ACO Profile Picture
    350 on at

    Inge:

    I believe you want to use xsi:noNamespaceSchemaLocation to point towards your XSD. For example:

    <PayrollDataSet xmlns:xsd="www.w3.org/.../XMLSchema" xmlns:xsi="www.w3.org/.../XMLSchema-instance" xsi:noNamespaceSchemaLocation="myserver.mydomain.local/PayrollDataSet.xsd">

    tempuri.org will not have the XSD.

    If there is no XSD, you should not reference it.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans