Use AI to interpret XML? My question is more about "is it possible?" and "is this the right approach?" So let me explain what my idea is:

I think about a system which gets XML documents in various structures but with essentially the same data structure in it. For the example, lets assume each document contains data about one or more persons. So the AI would recognize a name. Somewhere else in the document there is the post address of our fictional person. The AI should now "see" the address and conclude, it belongs to our person. Anywhere else, there is a phone number in the document. Again, our AI should see the connection between our person and this phone number.

This wouldn't be a job for an AI if there wasn't a catch. If the task was merely to find and map strings like addresses and phone numbers, we could simply use a regex to match our "target strings". The catch in this scenario would be this: the XML document might contain other data, which does not belong to our person but is a valid phone number for example and thus will match an regex.

So the big question is: Would it be possible for an AI to learn this and if yes, with which framework would someone create such an AI?



Sample XML document:

&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;document&gt;
    &lt;data&gt;
        &lt;foo&gt;
            &lt;bar&gt;
                &lt;person&gt;
                    &lt;name&gt;John Doe&lt;/name&gt;
                &lt;/person&gt;
            &lt;/bar&gt;
            &lt;address&gt;
                &lt;street&gt;Main street 1&lt;/street&gt;
                &lt;city&gt;1111 Twilight town&lt;/city&gt;
                &lt;country&gt;sample country&lt;/country&gt;
            &lt;/address&gt;
            &lt;phone&gt;+123 123 123&lt;/phone&gt;
        &lt;/foo&gt;
        &lt;foo&gt;
            &lt;bar&gt;
                &lt;person&gt;
                    &lt;name&gt;Jane Doe&lt;/name&gt;
                &lt;/person&gt;
            &lt;/bar&gt;
            &lt;address&gt;
                &lt;street&gt;Broadway 42&lt;/street&gt;
                &lt;city&gt;4521 Traverse town&lt;/city&gt;
                &lt;country&gt;sample country&lt;/country&gt;
            &lt;/address&gt;
            &lt;phone&gt;+123 412123&lt;/phone&gt;
        &lt;/foo&gt;
    &lt;/data&gt;
    &lt;creator&gt;
        &lt;!-- Note: While this looks like a valid person, --&gt;
        &lt;!-- this data should not be matched by the AI --&gt;
        &lt;name&gt;Sam Smith&lt;/name&gt;
        &lt;office&gt;
            &lt;street&gt;Seaside road 5&lt;/street&gt;
            &lt;city&gt;4521 Traverse town&lt;/city&gt;
            &lt;country&gt;sample country&lt;/country&gt;
        &lt;/office&gt;
        &lt;phone&gt;+123 555 555&lt;/phone&gt;
    &lt;/creator&gt;
&lt;/document&gt;
XML, HTML and less formal languages all respond quite nicely to being transformed or interrogated within a graph framework. XML and HTML are particularly useful in that they conform strictly to a tree-structure. That means that any good data components can be measured in terms of tree-distance to any other "good" data components. 

If you extract your regex-friendly terms and keep track of where within their tree they are found, you may be able to cast those values into a general document-space vector (it might only need to be one-dimensional), allowing you to identify clusters of "good" vs anomalous sections of "bad" data based on a simple distance metric, or anomaly detection algorithm - say an isolation-forest that runs on information density for example. 

This depends on your data, and how much of it you can find, ideally already tagged up containing good vs bad. 

If you're looking to scrape reliable address-contents, then yes, you're likely to score hits on names, addresses, postcodes and phone-numbers all appearing as tightly connected clustered groups, all within one or two nodes-distance from one another.

Meanwhile, an annotation containing a phone number lodged somewhere else is less likely to be a match. 

Different documents will have different threshold densities, and differing anomaly to conformant ratios, so you'd have a task on your hands to figure out some way to automatically tune your parameters on any given document set. 

In the past, I've tried doing this against html by flattening all the content into a single string of text and a similar approach yielded half-decent results, but if you're looking at XML, it's fair to expect the structure to yield more information.