Problem reading XML file
David_Singleton
Member Posts: 5,479
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:
But now they are using the following format
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.
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.
David Singleton
0
Comments
-
Hi,
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<?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> ...
Regards
Jedrzej0 -
JedrzejT wrote:Hi,
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?
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.David Singleton0 -
Those names are case sensitive, so make sure you get the case right. Did you check the MinOccurs and MaxOccurs properties?0
-
That was also my first assumption, so I copy pasted the texts to make sure.DenSter wrote:Those names are case sensitive, so make sure you get the case right.
In the end I went through and set them all to Zero.DenSter wrote:Did you check the MinOccurs and MaxOccurs properties?
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.David Singleton0 -
I know this is silly, but if you just change TagType from attributes to element.. ,maybe good thing will be just Delete whole Xml Line and create from scratch.. there are some other properties for other TagTypes.. which is saved even if you change TagType. I will try this just to be sure..0
-
I had a similar problem once, the problem was that the XMLport designer wouldn't let me indent the structure properly (some strange errors). After composing the XMLport from scratch the indentation worked properly.0
-
Good idea. I will give this a try. The issue seems to be that as an attribute for the old file, NAV (logically) gives me an "Unexpected element" error. But when I convert to Element it gives me an indentation error.JedrzejT wrote:I know this is silly, but if you just change TagType from attributes to element.. ,maybe good thing will be just Delete whole Xml Line and create from scratch.. there are some other properties for other TagTypes.. which is saved even if you change TagType. I will try this just to be sure..
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.SLF25 wrote:I had a similar problem once, the problem was that the XMLport designer wouldn't let me indent the structure properly (some strange errors). After composing the XMLport from scratch the indentation worked properly.David Singleton0 -
Hello David
Could you paste the whole xml. Preferably one with more than one record?0 -
ara3n wrote:Hello David
Could you paste the whole xml. Preferably one with more than one record?
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.David Singleton0 -
I think at this point recreating the XMLPort with the proper tagtypes would give you the best chance of success.0
-
I suggest to use XMLPort generator from download link.
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.0 -
ara3n wrote:I suggest to use XMLPort generator from download link.
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.
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.David Singleton0 -
Something that I've run into is that XMLPorts are very picky about the order of the elements and attributes. The XML must have everything in the exact same order as the XMLPort, or it's going to get cranky.0
-
DenSter wrote:Something that I've run into is that XMLPorts are very picky about the order of the elements and attributes. The XML must have everything in the exact same order as the XMLPort, or it's going to get cranky.
Yes I think that could be a problem. It looks like some parts of the file they swap the order like<?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> ... MyHeader> <HeaderReport> <MYOtherID>Joe_Blogs_99</MYOtherID> <MyIDID>654321</MyIDID> <AddressData>
urrrrgggggggDavid Singleton0 -
that's not only 'a' problem, but that is likely 'the' problem. If your XMLPort is set up along the lines of the first file, then while importing the second file you would get the 'unexpected element' error.
The incoming XML must always match 100% or the XMLPort will scream at you.0 -
DenSter wrote:that's not only 'a' problem, but that is likely 'the' problem. If your XMLPort is set up along the lines of the first file, then while importing the second file you would get the 'unexpected element' error.
The incoming XML must always match 100% or the XMLPort will scream at you.
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.David Singleton0 -
Actually you would have because I pointed that out to you in my last reply. Out of order elements is the number 1 cause of the error message in your original post, but I assumed you knew that so I didn't include that in my reply to the OP. Not until you mentioned the same error with another element did it dawn on me that you didn't know about that.David Singleton wrote: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.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

