473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Help with XPath


I am in the process of creating an application to scrape databases in order to create typed
DataSets. One of the last pieces that I need to do is to remap database fields to something
more pleasant.

In order to do this I have created a static map that will perform the transformation. Below is
a sample of an XML Schema that would be returned from the database. What I am looking
to do is given a column name, find the node.

For example: I want to change "st" to "State". Given "st" return the node head to
<xs:element name="st" type="xs:string" minOccurs="0" />

This will allow me to continue with what I need to do.

My question is how do I easily navigate to this node? I am not aware of this but what if there
column names that are the same in different tables?

Any help is appreciated.

Cheers,
Dave
==================================================

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="Summary" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Summary" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="addr1" type="xs:string" minOccurs="0" />
<xs:element name="addr2" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="st" type="xs:string" minOccurs="0" />
<xs:element name="zip" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="name_fi" type="xs:string" minOccurs="0" />
<xs:element name="name_ls" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Nov 12 '05 #1
3 1696
Are you looking for something like a mapping between the friendly name in
your schema and the actual name in the database? The closest to this that I
know of is the SQLXML Annotations.

http://msdn.microsoft.com/library/en...tions_0gqb.asp

--
Kirk Allen Evans
http://blogs.msdn.com/kaevans

-- This posting is provided "AS IS" with no warranties, and confers no
rights.
"David Elliott" <Da**********@BellSouth.net.nospam> wrote in message
news:2n********************************@4ax.com...

I am in the process of creating an application to scrape databases in order to create typed DataSets. One of the last pieces that I need to do is to remap database fields to something more pleasant.

In order to do this I have created a static map that will perform the transformation. Below is a sample of an XML Schema that would be returned from the database. What I am looking to do is given a column name, find the node.

For example: I want to change "st" to "State". Given "st" return the node head to <xs:element name="st" type="xs:string" minOccurs="0" />

This will allow me to continue with what I need to do.

My question is how do I easily navigate to this node? I am not aware of this but what if there column names that are the same in different tables?

Any help is appreciated.

Cheers,
Dave
==================================================

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="Summary" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Summary" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="addr1" type="xs:string" minOccurs="0" />
<xs:element name="addr2" type="xs:string" minOccurs="0" />
<xs:element name="city" type="xs:string" minOccurs="0" />
<xs:element name="st" type="xs:string" minOccurs="0" />
<xs:element name="zip" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="name_fi" type="xs:string" minOccurs="0" />
<xs:element name="name_ls" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

Nov 12 '05 #2
Yes. I know.
What I am looking for is how to navigate to the XML Node.

Cheers,
Dave
On Mon, 17 May 2004 19:07:49 -0400, "Kirk Allen Evans [MSFT]" <ki***@online.microsoft.com> wrote:
Are you looking for something like a mapping between the friendly name in
your schema and the actual name in the database? The closest to this that I
know of is the SQLXML Annotations.

http://msdn.microsoft.com/library/en...tions_0gqb.asp


Nov 12 '05 #3
AH! OK, sorry for the misread there.

You have 2 options for navigation. One is the use of XPath directly. You
simply need to qualify the namespace bindings using the XmlNamespaceManager.

Assume the following XML Schema. I created by dragging the
Northwind.Customers table onto the design surface of the DataSet designer,
and made a quick edit to create the named customerType complexType instead
of an anonymous type.

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="DataSet1" targetNamespace="http://tempuri.org/DataSet1.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/DataSet1.xsd"
xmlns:mstns="http://tempuri.org/DataSet1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:complexType name="customerType">
<xs:sequence>
<xs:element name="CustomerID" type="xs:string" />
<xs:element name="CompanyName" type="xs:string" />
<xs:element name="ContactName" type="xs:string" minOccurs="0" />
<xs:element name="ContactTitle" type="xs:string" minOccurs="0" />
<xs:element name="Address" type="xs:string" minOccurs="0" />
<xs:element name="City" type="xs:string" minOccurs="0" />
<xs:element name="Region" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="Country" type="xs:string" minOccurs="0" />
<xs:element name="Phone" type="xs:string" minOccurs="0" />
<xs:element name="Fax" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>

<xs:element name="DataSet1" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Customers" type="mstns:customerType" />
</xs:choice>
</xs:complexType>
<xs:unique name="DataSet1Key1" msdata:PrimaryKey="true">
<xs:selector xpath=".//mstns:Customers" />
<xs:field xpath="mstns:CustomerID" />
</xs:unique>
</xs:element>
</xs:schema>

The XPath to match the "Region" definition in the customerType complexType
looks like:

/xs:schema/xs:complexType[@name='customerType']/xs:sequence/xs:element[@name
='Region']

The other option is to navigate using the Schema Object Model (SOM). The
SOM is represented in the System.Xml.Schema namespace. There is an example
of working with the SOM in the SDK:

http://msdn.microsoft.com/library/en...ClassTopic.asp

--
Kirk Allen Evans
http://blogs.msdn.com/kaevans

-- This posting is provided "AS IS" with no warranties, and confers no
rights.

"David Elliott" <Da**********@BellSouth.net.nospam> wrote in message
news:pv********************************@4ax.com...
Yes. I know.
What I am looking for is how to navigate to the XML Node.

Cheers,
Dave
On Mon, 17 May 2004 19:07:49 -0400, "Kirk Allen Evans [MSFT]" <ki***@online.microsoft.com> wrote:
Are you looking for something like a mapping between the friendly name in
your schema and the actual name in the database? The closest to this that Iknow of is the SQLXML Annotations.

http://msdn.microsoft.com/library/en...tations_0gqb.a

sp

Nov 12 '05 #4

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

Similar topics

4
by: MegaZone | last post by:
I'm having some issues with PHP DOMXML - in particular the get_elements_by_tagname method. Now, the PGP docs on this are, well, sparse, so maybe I'm just doing something stupid. I thought this...
0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="success">1</para> I can't figure out what kind of python xml.dom codes I should invoke to read the data 1? Any help please? Thanks...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
3
by: John Lee | last post by:
Hi, I have a document <root> <name>John</name> </root> and the xpath "//name" will return correct node by using xmldoc.SelectSingleNode(xpath) and if the document contains a default...
7
by: Peter Morris [Droopy eyes software] | last post by:
Hi all I need a little help with XSD, here is my XML <data> <brandData> <brandGroups> <brandGroup> <name>Group1</name> </brandGroup>
1
by: Showjumper | last post by:
Hi, I need some help with xpath. I am very unfamilair with XPATH. I have an xml file with the folloing structure: <Photos> <Photo> <Description>This is a photo of horse that colicked. The bowel...
2
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...
0
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...

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.