XML Namespace issue

FlorisB1984
Member Posts: 17
Hi Guys,
I need to create an xml file which exports data out of nav. I use the following code:
WITH XMLDOMMgt DO BEGIN
IF NOT ISCLEAR(XMLDoc) THEN
CLEAR(XMLDoc);
CLEAR(XMLCurrentElement);
CREATE(XMLDoc);
ProcIns := XMLDoc.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');
XMLDoc.appendChild(ProcIns);
// CreateRootElement
CurrNode := XMLDoc.createElement('data');
CurrNode := XMLDoc.appendChild(CurrNode);
NameSpace := '';
AddAttribute(CurrNode,'xmlns','http://www.somesite.eu/nl');
AddAttribute(CurrNode,'xmlns:common','http://www.somesite.eu/schema/common');
AddAttribute(CurrNode, 'xmlns:xsi','http://www.w3c.org/2001/XMLSchema-instance');
When I run this, I get the following error:
The call to member createAttribute failed. msxml3.dll returned the following message:
The namespace prefix is not allowed to start with the reserved string "xml".
I need to add the namespace prefixes, otherwise my xmlfile will not be excepted. can someone help me with this?
Best regards,
Floris
I need to create an xml file which exports data out of nav. I use the following code:
WITH XMLDOMMgt DO BEGIN
IF NOT ISCLEAR(XMLDoc) THEN
CLEAR(XMLDoc);
CLEAR(XMLCurrentElement);
CREATE(XMLDoc);
ProcIns := XMLDoc.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"');
XMLDoc.appendChild(ProcIns);
// CreateRootElement
CurrNode := XMLDoc.createElement('data');
CurrNode := XMLDoc.appendChild(CurrNode);
NameSpace := '';
AddAttribute(CurrNode,'xmlns','http://www.somesite.eu/nl');
AddAttribute(CurrNode,'xmlns:common','http://www.somesite.eu/schema/common');
AddAttribute(CurrNode, 'xmlns:xsi','http://www.w3c.org/2001/XMLSchema-instance');
When I run this, I get the following error:
The call to member createAttribute failed. msxml3.dll returned the following message:
The namespace prefix is not allowed to start with the reserved string "xml".
I need to add the namespace prefixes, otherwise my xmlfile will not be excepted. can someone help me with this?
Best regards,
Floris
0
Comments
-
Hi Floris
Have a look into Codeunit 6224, Function AddAttribute. A namespace is added by DOM function "setNamedItem".
You call it then like
xmlMgt.AddAttribute(CurrNode,'xmlns:commons','http://www.common.com/xmlns/common1/');
Hope this helps
Thomas0 -
Hi Thomas,
Thanks for your reply!
In my code I'm already using the XML dom management codeunit. I'm exactly in the same way adding the new namespace.
best regards,
Floris0 -
I have tested with MS XML 3.0 and MS XML 6.0. With 6.0 it works as expected, with 3.0 it doesnt.
If you can, I would suggest you use 6.0, but be careful if its a part of a bigger application, 6.0 has quite some differences to 3.0, for example the standard values in properties, etc.
Hope this helps.
Thomas0 -
Hi Thomas,
Thanks again!
I've changed the automations to sml 6, but that did not solve my issue. It still complains about the xml version 3 dll. What am I doing wrong?
Best regards,
Floris0 -
Hi Thomas,
I wasn't thinking straight, I know what you mean. And it works, thanks!
What I needed to do, was create new function in my code unit and do the same thing als AddAttribute in codeunit 6224.
best regards,
Floris0 -
Hi Floris
[Edit: Sorry, didnt note your answer.]
Very strange. Please find my test codeunit in the following code section. It works, as long as the automation objects are in version 6.0OBJECT Codeunit 50901 xml test 2 { OBJECT-PROPERTIES { Date=16.12.10; Time=15:39:16; Modified=Yes; Version List=; } PROPERTIES { OnRun=VAR XMLDoc@1103030003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60"; ProcIns@1103030002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF89-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMProcessingInstruction"; CurrNode@1103030001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode"; NewChild@1103030000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode"; NameSpace@1103030004 : Text[30]; XMLDOMMgt@1103030005 : Codeunit 6224; BEGIN CREATE(XMLDoc); ProcIns := XMLDoc.createProcessingInstruction('xml','version="1.0" encoding="UTF-8"'); XMLDoc.appendChild(ProcIns); // CreateRootElement CurrNode := XMLDoc.createElement('data'); CurrNode := XMLDoc.appendChild(CurrNode); NameSpace := ''; XMLDOMMgt.AddAttribute(CurrNode,'xmlns','http://www.somesite.eu/nl'); XMLDOMMgt.AddAttribute(CurrNode,'xmlns:common','http://www.somesite.eu/schema/common'); XMLDOMMgt.AddAttribute(CurrNode, 'xmlns:xsi','http://www.w3c.org/2001/XMLSchema-instance'); XMLDoc.save('c:\temp\1.xml'); END; } CODE { BEGIN END. } }
0 -
Hi Thomas,
I'm running into the next issue. The company I have to send the xml to requeres the following nodes:
<common:sender>
After added the prefix xmlns:common I assumed it would work..... but it doesn't. Do you perhaps know how that is done? Or is the following xml code the same:
<common:sender xmlns:common="common">
best regards,
Floris0 -
Hi Floris
Imho the Element should look like that
<common:sender> ==> Element Name with name space prefix
or
<sender xmlns:common="common"> ==> Element Name with name space as a kind of attribute.
If you can choose, I suggest the first method.
Thomas0 -
I can't choose
So I'll have to go with the second option.
Thans again!
Floris0 -
Good luck!
And by the way: There are normally 2 different ways for the target system to load the xml.
1: Load it as text or read it by other sequential means like sax.
2: Load it as XML DOM
In case 2, there is no difference between different "dialects", the meaning stays the same. In case one, tags etc. must excactly match.
Thomas0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions