Because I said about the XML coming from "
myself said:
I can convert it to one cursor with XMLToCursor
The method to load XML into an XMLAdapter class is the more general way to even be able to detect multiple tables in the XML. But then the contradiction of XMLToCursor pulling in all data, not just the first 10% of the XML and the iteration on XMLAdapters.Tables collection.
Again, XML is not just a tool to store table data. It's far generally hierarchical data and it even tends to nest details with the parent nodes instead of separating that into parent/child table with relation, the relation is being nested into a parent node, it's like subobjects with a parent object are pointing to it simply by a reference pointer, not a foreign key/parent key ID pair. So the concepts of XML and databases are not really a match.
In that case, XMLAdapter fails to see many more tables by misjudging the structure. But the better analysis of the problem is in what I said later:
myself said:
The nature of the XML is to nest joined data into the records XML elements of the main table sndList, this why you can't parse out or convert the single tables, you have to post process the one cursor you get to extract the records in a "normalized" way. It is your start point for your postprocessing unless you find empty list fields, where there should be detail-data. But I can't judge that for you.
I can't judge, so how should code be able to judge? This requires internal knowledge about the meaning. You have to know about what the XML means, how it was constructed and what relations the nodes have, that's not self-descriptive. What's technically clear about this snd.xml is that it contains one sndList, that's the start and end tag. From that it's already wrong to see 10 tables, but then it is actually so that this one list contains many sections, which XMLToCursor interprets as fields, and loads these XML sections.
Both tools XMLAdapter and XMLToCursor are not AI, very mechanical and so not perfect. StrExtract also isn't, but for StrExtract any surrounding context doesn't matter. As long as you're sure the XML you receive is about one contact and the first name is in some <fname> tag, you can use StrExtract(), though. That makes it more stable for this task. Once this becomes XML about multiple persons you'll need to first see how to separate them and then find their own <fname> tag. So once you know some XML is about one record and you seek out one field of it, it's very natural to use StrExtract and not care about the XML more than perhaps seeing what kind of codepage conversion you need to do about the extracted text. But that's also no final truth.
It's just like a query to a database, you can only make sense of a database or a subset taken from it by knowing what relations exist, what tables and fields mean, the semantic isn't in the structure alone. That's what I continually say.
So to write correct code about some XML Web Service you have to know the method, it's result XML on top of the Soap protocol part that's automatically handled for you when using WSDL. In this case that's not the case, though, it's simply a huge XML file from the start. And for example firefox tells "No stylesheet information are linked to this XML (so no XMLSN, no XML schema, no DTD." which would at least be a technical readable information about the structure, still not the semantics. And Firefox then says "The following shows the tree-view of the document", and that tells what's the only general truth about XML, that it is a hierarchical tree of nodes, always.
It boils down to needing to initially know how this tree is structured on an abstract level, what you have to expect in nodes, what repeats how, is nested into which other node, just like you need to know table and field names and relations of tables to query them with sensible queries. So XML always has to come with how to interpret it or you can only fall back to its hierarchival structure, nodes are named brackets containing (nesting) something.
You find better possibilities to deal with XML in other languages. I mean, you can blame this to the parsers in MSXML3 and 4, but that's also what VFP XML functions are always stuck with. The Webbrowser control in contrast, for example, always uses the browser canvas of the most current IE Version installed. The VFP team decided to stick with specific versions to be able to ensure the usage works forever. And it's also somewhat okay, because you don't gain better XML interpretations by later MSXML versions, the problem of XML not transporting its own meaning is inherent, SQL database tables also don't tell how they are meant, there's just more meta info about relationships, for example, when the database designer puts it in, at least.
The nesting of XML inside its nodes is only a sign of a general relationship of a certain XML node structure to a parent node, when it repeats the same way, so each single nesting doesn't establish a general relationship, just the relationship of the child node XML to this exact one parent node. In database sense that's means generally unstructured data, JSON is the same, just less complex than XML. There only is an overlap of these worlds as XML is indeed also used to make more restricted use of them. And ever so often people chunking out some XML do nobody a favor by not documenting what it is, neither with a technical schema and even less so with human readable just natural text descriptions of what this is about. Just like a class library needs a documentation of what to use which methods for to make good use of it and the only chance to dive into a library use is you already know about the topic of it, have the right expectations about how it works.
So just don't look for the simple recipe you can always use. This is always individually different.
You can find XML structures that programmers use more often than just what would be possible randomy, because you want to use XML to structure data, obviously. You can easily categorize XML in one further simple way: With or without repeating inner structures. Those identify to you whether this is about a record or a head structure. Configurtion XML consisting of options and values will usually have no repeating nodes, it may be as simple as a single record of a number of fields named by the option containing the setting value. It may also be seen as n records of key name and value and interpreted as key/value store. And it may be that one of the options has a nested substrucutre and so it neither fits key&/value nor a record. XML in the end is more like a complex object with subobjects with the catch-22 I mentioned about even that not working for repeated nodes within the same parent node. Because a hierarchy can do things tables can't. Unlike rows of a table, child nodes don't need to care about being the same composition of nodes, even when the are nested with the same type of parent node as another group od child nodes. If you convert a table into XML that is what you get, but you don't always have that and acn't always convert XML into a row structure. And then, last not least, the way we database people see a tree usually with a self referencing table or perhaps a hierarchy of tables is also not something that needs to fit on any XML, so there is no general 1:1 relationship of XML and a table structure you could extract from any XML.
All this will fall into place once you really just dig into what XML is, maybe start much smaller and try a bit of HTML, XML with a fixed set of nodes that also have a fixed meaning, it's all about why this all is nested and how easy you already can have nesting errors by start tags appearing in a paernt tag pair, while end tag is outside of it, just like [ { ] } wouldn't be a valid bracketing. XML is very fragile, actually because it's open to anything.
To get more concrete again, for example Twitter has a very good documentation. It once also was about the optional XML results you could get, today it all seems JSON, but a good portion of JSON nesting nodes still is the same as XML. And here's a very good example of response fields:
It's still important to understand that this notion is more about what object properties are, not table fields. And the field types also being arrays tell you about the properties that area actually a list of objects themselves, again, the nesting.
And the final final truth about this is ou can never expect any complex nor simple parsing extraction to always work and extract all information from the XML into an object or a table or a few tables and objects. But you can always start by the root XML node and traverse a tree "vertically" or "horizontally" first (drilling down children or visiting siblings. And in XML that should have tables in it none of both is really the best way forward, you need to already know what nodess being sections of repeated nodes you will find inside. Just like you know the very low level detail of finding an fname node. Just beware of the future case there are two or three and you only extract one.
Bye, Olaf.
Olaf Doschke Software Engineering