473,789 Members | 2,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem understanding what XPATH to write

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:complexTy pe name="PHONENO">
<xs:sequence maxOccurs="unbo unded">
<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>88732 3</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>88732 3</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>88732 3</NUMBER>
<EXCHANGE>Banbu ry 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)

Jul 20 '05 #1
4 1972
In article <10************ ****@spandrell. news.uk.clara.n et>,
Clarence <an**@anon.co m> wrote:
<xs:complexTyp e name="PHONENO">
<xs:sequence maxOccurs="unbo unded">
<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>


Do you really want that maxOccurs="unbo unded"? And from what you say
lower down, you don't seem to care about the order.

You seem to be wanting to find elements called PHONENO that contain a
COUNTRY, a NUMBER, an AREACODE and nothing else. If so, this will
match such an element:

PHONENO[count(*) = 3 and COUNTRY and NUMBER and AREACODE]

If you want to discover whether there is one of those within the current
element,

.//PHONENO[count(*) = 3 and COUNTRY and NUMBER and AREACODE]

-- Richard
Jul 20 '05 #2
On 6 Oct 2004 14:21:40 GMT, Richard Tobin <ri*****@cogsci .ed.ac.uk> wrote:
In article <10************ ****@spandrell. news.uk.clara.n et>,
Clarence <an**@anon.co m> wrote:
<xs:complexTy pe name="PHONENO">
<xs:sequence maxOccurs="unbo unded">
<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>


Do you really want that maxOccurs="unbo unded"? And from what you say
lower down, you don't seem to care about the order.


If "maxOccurs" should really be "unbounded" , you could use:

count(*) div (4*count(COUNTR Y)*count(AREACO DE)*count(NUMBE R)) &lt; 1
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3
WOAAAAAH, THANK YOU!!!!

Do you really want that maxOccurs="unbo unded"? And from what you say
lower down, you don't seem to care about the order.
I don't care about the order you are right. Your observation above just
reflects my limited understanding of what I wrote :( I put this there
because some companies have more than one PHONENO and I thought I was making
things easier for people to help me out.
If you want to discover whether there is one of those within the current
element,

.//PHONENO[count(*) = 3 and COUNTRY and NUMBER and AREACODE]
Exactly what I was looking for. I was missing the count(*) bit in my code.

Thank you again Richard. Very clear answer.
Clarence

"Richard Tobin" <ri*****@cogsci .ed.ac.uk> wrote in message
news:ck******** ***@pc-news.cogsci.ed. ac.uk... In article <10************ ****@spandrell. news.uk.clara.n et>,
Clarence <an**@anon.co m> wrote:
<xs:complexTy pe name="PHONENO">
<xs:sequence maxOccurs="unbo unded">
<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>


Do you really want that maxOccurs="unbo unded"? And from what you say
lower down, you don't seem to care about the order.

You seem to be wanting to find elements called PHONENO that contain a
COUNTRY, a NUMBER, an AREACODE and nothing else. If so, this will
match such an element:

PHONENO[count(*) = 3 and COUNTRY and NUMBER and AREACODE]

If you want to discover whether there is one of those within the current
element,

.//PHONENO[count(*) = 3 and COUNTRY and NUMBER and AREACODE]

-- Richard

Jul 20 '05 #4

You guys have got to stop this, there will be nothing left for me to do.
Thank you too Joris.
"Joris Gillis" <ro**@pandora.b e> wrote in message
news:op******** ******@news.pan dora.be...
On 6 Oct 2004 14:21:40 GMT, Richard Tobin <ri*****@cogsci .ed.ac.uk> wrote:
In article <10************ ****@spandrell. news.uk.clara.n et>,
Clarence <an**@anon.co m> wrote:
<xs:complexTy pe name="PHONENO">
<xs:sequence maxOccurs="unbo unded">
<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>


Do you really want that maxOccurs="unbo unded"? And from what you say
lower down, you don't seem to care about the order.


If "maxOccurs" should really be "unbounded" , you could use:

count(*) div (4*count(COUNTR Y)*count(AREACO DE)*count(NUMBE R)) &lt; 1
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1823
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings are stored in a free-format XML document (in memory for the life of the session) and persisted to a database (as free text) on exit. I have taught my developers the basics of XPath, however I don't want to have to review XMLDOM code all over the...
1
6826
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
13
2514
by: tfsquare | last post by:
All, I am new to XSLT and having some problems understanding the syntax of XPath which selects nodes in the XML document. Consider this bit of XML, which contains three outer XML elements. <FOO>foo.top.level</FOO> <BOO><FOO>foo.second.level</FOO></BOO> <CHOO><BOO><FOO>foo.third.level</FOO></BOO></CHOO>
3
1745
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't require that you enter the xpath expression. It may have been something that worked from opening a page in IE. That would be OK. It could have been
8
5112
by: Lawrence Oluyede | last post by:
Is there a way to treat html tags like simple text? I explain myself, if I have a bunch of xml like <content type="application/xhtml+xml" xml:base="http://loluyede.blogspot.com" xml:lang="en-US" xml:space="preserve"> <div xmlns="http://www.w3.org/1999/xhtml">I have 3 accounts to give away, let me know if you want them</div> </content>
2
2882
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file - "xmlns="http://tempuri.org/nameOfRoot.xsd" I have no idea what its pointing to & what is tempuri.org? So when this tag is in my xml tag my xpath query never works. But when I delete it work fine.
2
1645
by: Pawel | last post by:
I have small problem with XslTransformation. I get from WebService xml document. I have xslt and I want transform xml document to html code. It's look easy but I cant't manage with xPath. Maybe someone help me with that. I have problems with xPath in xslt file. I can't navigate by names only by vertical and horizontal axis. What's wrong .... --- Code --- // WebService XmlForAnalysis.Xmla xa = new XmlForAnalysis.Xmla(); xa.Url =...
5
4540
by: RolfK | last post by:
Dear ALL, I'm writing some first examples to get a better understanding of XSLT/ XPATH2.0. Please excute this code, any xml input is OK. I'm using saxon. The example runs perfect with ALTOVA, but fails with SAXON. Please refere to line with element <matcheswhich is quite close to the error.
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.