Hi guys.
I have a problem that I can not resolve and need some help. I am trying to import an XML file with no luck. When we started the XML file looked something like this:
<?xml version="1.0" encoding="utf-8"?>
<MyHeader>
<HeaderReport MyIDID="123456" MYOtherID="Fred_Blogs_99">
<AddressData Street="21 Smith Street" ZipCode="12345" Town="XYZZY">
...
But now they are using the following format
<?xml version="1.0" encoding="utf-8"?>
<MyHeader>
<HeaderReport>
<MyIDID>123456</MyIDID>
<MYOtherID>Fred_Blogs_99</MYOtherID>
<AddressData>
<Street>21 Smith Street</Street>
<ZipCode>12345</ZipCode>
<Town>XYZZY</Town>
</AddressData>
...
Both are pretty standard XML formats, but when I import the second file I get an error message
The Element HeaderReport was not expected.
So it thinks that the next attribute is an element.
Shouldn't Navision just accept XML in either of these formats?
Thanks in advance, I have been banging my head trying to figure this one.
(By the way I made up the data above, so don't take it too literally, I am only concerned about the two different formats.
Comments
For me only one diffrence is that the MyIDID and MYOtherID is now elements (was attributes before)
Should be no problem with importing after change that 2 attributes for elements.. but i suppose You do it already and still not working? You do it via XmlPort?
I see after edit.. there is some change in structure.
This look like wrong xml format.. HeaderReport should be ended before AddresData is started.. because it is the same indent
Regards
Jedrzej
Yes its an xml port and I changed the attributes to Elements, but then got an error about incorrect indentation. I am missing something really simple here and just can't see it.
Don't worry about the incorrect close, I just wrote that xml snipped manually into the mibuso editor. The actual file contains confidential information that I can't post.
Thanks for your help.
RIS Plus, LLC
In the end I went through and set them all to Zero.
I am sure I just missed something really silly.
Actually I when I first started, I got this error:
Microsoft Dynamics NAV
The XML Parser setup fails.
Error = 80040154 Code meaning = Class not registered
OK
which seems to stem from installing 2009 that over writes a DLL. So I am now working on a different computer as well.
This particular XML just hates me.
And yes that is about where I am now, If Jedrzej's solution doesn't work then I am going to build the whole thing again.
Could you paste the whole xml. Preferably one with more than one record?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Unfortunately it's customer confidential information. The snippet above is just to indicate the issue between attributes and elements. I know its not really a lot to go on, I was just hoping that someone might have seen a similar issue and have a silver bullet.
RIS Plus, LLC
You need to open the xml file in visual studio. click on xml menu and select generate xsd.
Then in XMLPortGenerator select this xsd. The tool will create the xlmport for you. Very time saving app.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Sorry for not getting back to you all.
Yes Rashed this tool is brilliant. I used XSD.exe to convert xsd from the XML then created the XML. It looked identical to mine, but gave different error messages. So I think that converting from attributes to Elements (as mentioned above) there were some left over properties.
BUT
Still errors, now its a different Element that it does not expect, even though that element is in the XMLport.
I think the issue has to be int he formatting of the document it self. So I have converted the current XML files to SV to import them and will start again with a clean ML file with a single record and try it from there.
This particular xml really hates me.
RIS Plus, LLC
Yes I think that could be a problem. It looks like some parts of the file they swap the order like
urrrrggggggg
The incoming XML must always match 100% or the XMLPort will scream at you.
RIS Plus, LLC
No I mean elements in the same file. I would have assumed the XSD generator to give an error message when created the schema.
But yes I am pretty sure that this is the root cause of all the problems. And I probably would never have found it without theXML generator.
The problem is trying to find the incorrect sequence in the thousands of lines and then handing it back to the vendor as "Their problem". The error message just tells you there is an unexpected element but doesn't say where, not even a line number.
I think I can solve this now though so thanks to everyone for the help.
RIS Plus, LLC