C
Clarence
Hi - I have a problem and here is the verbose version of what I am trying to
do (better too much info than not enough).
I am searching through about 4,700 XML files containing company contact
details. In the company details are phone numbers. The phone numbers with
the formats I need have the following structure.
<xs:complexType name="PHONENO">
<xs:sequence maxOccurs="unbounded">
<xs:element name="COUNTRY" type="xs:string"/>
<xs:element name="NUMBER" type="xs:string"/>
<xs:element name="AREACODE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
I have determined this structure and I don't have a schema for the XML files
I am searching. Many of these files have many different XML structures but
the structure of the phone numbers is always the same.
My question is how do I tell if a bit of XML contains this PHONENO structure
(above)? What is a typical XPATH expression I could use to search my XML to
return a result saying Yes, this is a valid bit of XML containing the phone
number or no it isn't?
For example, for the following bit of XML I want a result (using XPATH?) to
say that the complex type PHONENO exists
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<NUMBER>887323</NUMBER>
<AREACODE>01865</AREACODE>
</PHONENO>
</COMPANY>
I want a result using XPATH to say that the complex type PHONENO exists too.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
<NUMBER>887323</NUMBER>
</PHONENO>
</COMPANY>
However for the following THREE bits of XML, representative of the XML in my
files, I want the result using XPATH to say that the complex type PHONENO
does NOT exist.
This bit of XML has no PHONENO at all.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<ADDRESS>18 St Giles Street</ADDRESS>
<ADDRESS>Carfax</ADDRESS>
<ADDRESS>Oxford</ADDRESS>
</COMPANY>
This bit is missing the <NUMBER> element in PHONENO and therefore since
every element in type PHONENO isn't present, it doesn't contain the
structure I want.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
</PHONENO>
</COMPANY>
This bit of XML doesn't have the structure of PHONENO in it that I want
either, the PHONENO in this XML has an extra element EXCHANGE and therefore
isn't the same as the complex type phone number defined above.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
<NUMBER>887323</NUMBER>
<EXCHANGE>Banbury 1183</EXCHANGE>
</PHONENO>
</COMPANY>
I'm not sure whether this is difficult of easy but I am certain that it has
taken me a long time thinking about it before making this post.
Thanks for everyone thinking about this.
Clarence (this is for home use, not for a job)
do (better too much info than not enough).
I am searching through about 4,700 XML files containing company contact
details. In the company details are phone numbers. The phone numbers with
the formats I need have the following structure.
<xs:complexType name="PHONENO">
<xs:sequence maxOccurs="unbounded">
<xs:element name="COUNTRY" type="xs:string"/>
<xs:element name="NUMBER" type="xs:string"/>
<xs:element name="AREACODE" type="xs:string"/>
</xs:sequence>
</xs:complexType>
I have determined this structure and I don't have a schema for the XML files
I am searching. Many of these files have many different XML structures but
the structure of the phone numbers is always the same.
My question is how do I tell if a bit of XML contains this PHONENO structure
(above)? What is a typical XPATH expression I could use to search my XML to
return a result saying Yes, this is a valid bit of XML containing the phone
number or no it isn't?
For example, for the following bit of XML I want a result (using XPATH?) to
say that the complex type PHONENO exists
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<NUMBER>887323</NUMBER>
<AREACODE>01865</AREACODE>
</PHONENO>
</COMPANY>
I want a result using XPATH to say that the complex type PHONENO exists too.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
<NUMBER>887323</NUMBER>
</PHONENO>
</COMPANY>
However for the following THREE bits of XML, representative of the XML in my
files, I want the result using XPATH to say that the complex type PHONENO
does NOT exist.
This bit of XML has no PHONENO at all.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<ADDRESS>18 St Giles Street</ADDRESS>
<ADDRESS>Carfax</ADDRESS>
<ADDRESS>Oxford</ADDRESS>
</COMPANY>
This bit is missing the <NUMBER> element in PHONENO and therefore since
every element in type PHONENO isn't present, it doesn't contain the
structure I want.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
</PHONENO>
</COMPANY>
This bit of XML doesn't have the structure of PHONENO in it that I want
either, the PHONENO in this XML has an extra element EXCHANGE and therefore
isn't the same as the complex type phone number defined above.
<COMPANY>
<NAME>ACME Manufacturing</NAME>
<PHONENO>
<COUNTRY>UK</COUNTRY>
<AREACODE>01865</AREACODE>
<NUMBER>887323</NUMBER>
<EXCHANGE>Banbury 1183</EXCHANGE>
</PHONENO>
</COMPANY>
I'm not sure whether this is difficult of easy but I am certain that it has
taken me a long time thinking about it before making this post.
Thanks for everyone thinking about this.
Clarence (this is for home use, not for a job)