473,388 Members | 1,213 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,388 software developers and data experts.

How to change the the attribute's name???

Isz
Hi Group:

I would like to know if it is possible to change the name of an
attribute to something else. My setup is like this: I have serveral SQL
tables that I nest and join so that it all outputs into a nice XML file
for the purpose of populating a flash navigation menu.

<NewDataSet>
<mainMenu_category menu_name="Home" menu_ID="1">
<menu menu_ID="1" />
</mainMenu_category> <mainMenu_category menu_name="Product"
menu_ID="2">
<menu category_name="28.5 Volt DC Power Carts" menu_ID="2" /> <menu
category_name="AC 400 Hz. Power Carts" menu_ID="2" /> <menu
category_name="Oxygen and Nitrogen Carts" menu_ID="2" /> <menu
category_name="Tow Bars" menu_ID="2" />
</mainMenu_category> <mainMenu_category menu_name="Business Info"
menu_ID="3">
<menu category_name1="Contact Info" menu_ID="3" /> <menu
category_name1="Email Us" menu_ID="3" /> <menu category_name1="Site
Designed By..." menu_ID="3" />
</mainMenu_category> <mainMenu_category menu_name="Admin" menu_ID="4">
<menu category_name2="Sign In" menu_ID="4" /> <menu
category_name2="Sign Out" menu_ID="4" /> <menu
category_name2="Create New Account" menu_ID="4" /> <menu
category_name2="Manage Accounts" menu_ID="4" /> <menu
category_name2="Product Update" menu_ID="4" /> <menu
category_name2="Contact Info Update" menu_ID="4" /> <menu
category_name2="List Server Update" menu_ID="4" />
</mainMenu_category>
</NewDataSet>

There are 3 joined SQL tables (home_category, product_category,
business_category, and admin_category) which all have a column named
category_name, but the XSD generated by the dataset renames these fields
to category_name, category_name1, category_name2. This makes sense since
these field needs to be correctly mapped to the appropriate menu_ID of
the parent SQL table called mainMenu_category.

But I don't like these names because my parser in my flash document
doesn't like them. They need to all be named "att0" and "att1". Like
this...

<NewDataSet>
<mainMenu_category att0="Home" att1="1">
<menu att1="1" />
</mainMenu_category> <mainMenu_category att0="Product" att1="2">
<menu att0="28.5 Volt DC Power Carts" att1="2" />
<menu att0="AC 400Hz. Power Carts" att1="2" />
<menu att0="Oxygen and Nitrogen Carts" att1="2" />
<menu att0="Tow Bars" att1="2" />
</mainMenu_category> <mainMenu_categoryatt0="Business Info" att1="3">
<menu att0="Contact Info" menu_ID="3" />
<menu att0="Email Us" menu_ID="3" />
<menu att0="Site Designed By..." att1="3" />
</mainMenu_category> <mainMenu_category att0="Admin" att1="4">
<menu att0="Sign In" att1="4" />
<menu att0="Sign Out" att1="4" />
<menu att0="Create New Account" att1="4" />
<menu att0="ManageAccounts" att1="4" />
<menu att0="Product Update" att1="4" />
<menuatt0="Contact Info Update" att1="4" />
<menu att0="List ServerUpdate" att1="4" />
</mainMenu_category>
</NewDataSet>

Here is the schema...

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="mainMenu_category">
<xs:complexType>
<xs:sequence>
<xs:element name="menu"
minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute
name="category_name" type="xs:string" />
<xs:attribute
name="category_name1" type="xs:string" />
<xs:attribute
name="category_name2" type="xs:string" />
<xs:attribute
name="menu_ID" type="xs:int" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="menu_name"
type="xs:string" />
<xs:attribute name="menu_ID"
type="xs:int" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//mainMenu_category" />
<xs:field xpath="@menu_ID" />
</xs:unique>
<xs:keyref name="custOrders" refer="Constraint1"
msdata:IsNested="true">
<xs:selector xpath=".//menu" />
<xs:field xpath="@menu_ID" />
</xs:keyref>
</xs:element>
</xs:schema>

Here is my C# code:
string sql1 = "SELECT menu_name, menu_ID";
sql1 += " FROM mainMenu_category";

string sql2 = "SELECT product_category.category_name,
business_category.category_name, admin_category.category_name,
menu.menu_ID";
sql2 += " FROM menu";
sql2 += " FULL JOIN product_category ON
(menu.product_category_ID = product_category.category_ID)";
sql2 += " FULL JOIN business_category ON
(menu.business_category_ID = business_category.category_ID)";
sql2 += " FULL JOIN admin_category ON
(menu.admin_category_ID = admin_category.category_ID)";
sql2 += " ORDER BY menu_ID,
product_category.category_order, business_category.category_order,
admin_category.category_order";

SqlConnection dataConn = new SqlConnection
(SQLconnStr);

dataConn.Open();

SqlDataAdapter sqlAdap1 = new SqlDataAdapter(sql1,
dataConn);
SqlDataAdapter sqlAdap2 = new SqlDataAdapter(sql2,
dataConn);

DataSet ds = new DataSet();
sqlAdap1.Fill(ds, "mainMenu_category");
sqlAdap2.Fill(ds, "menu");

dataConn.Close() ;

DataRelation rel = ds.Relations.Add("custOrders",
ds.Tables["mainMenu_category"].Columns["menu_ID"], ds.Tables
["menu"].Columns["menu_ID"]);
rel.Nested = true;

foreach ( DataTable dt in ds.Tables )
{
foreach ( DataColumn col in dt.Columns )
{
col.ColumnMapping = MappingType.Attribute;
}
}

ds.WriteXmlSchema(@"c:\myDS.xsd");
Response.Write(ds.GetXml());
So how do you change the attribute name "category_name" to attribute
name "att0"???

Thanks!
Nov 12 '05 #1
2 2944
how about XSLT?

"Isz" <so*******@nowhere.net> wrote in message
news:UL********************@giganews.com...
Hi Group:

I would like to know if it is possible to change the name of an
attribute to something else. My setup is like this: I have serveral SQL
tables that I nest and join so that it all outputs into a nice XML file
for the purpose of populating a flash navigation menu.

<NewDataSet>
<mainMenu_category menu_name="Home" menu_ID="1">
<menu menu_ID="1" />
</mainMenu_category> <mainMenu_category menu_name="Product"
menu_ID="2">
<menu category_name="28.5 Volt DC Power Carts" menu_ID="2" /> <menu
category_name="AC 400 Hz. Power Carts" menu_ID="2" /> <menu
category_name="Oxygen and Nitrogen Carts" menu_ID="2" /> <menu
category_name="Tow Bars" menu_ID="2" />
</mainMenu_category> <mainMenu_category menu_name="Business Info"
menu_ID="3">
<menu category_name1="Contact Info" menu_ID="3" /> <menu
category_name1="Email Us" menu_ID="3" /> <menu category_name1="Site
Designed By..." menu_ID="3" />
</mainMenu_category> <mainMenu_category menu_name="Admin" menu_ID="4">
<menu category_name2="Sign In" menu_ID="4" /> <menu
category_name2="Sign Out" menu_ID="4" /> <menu
category_name2="Create New Account" menu_ID="4" /> <menu
category_name2="Manage Accounts" menu_ID="4" /> <menu
category_name2="Product Update" menu_ID="4" /> <menu
category_name2="Contact Info Update" menu_ID="4" /> <menu
category_name2="List Server Update" menu_ID="4" />
</mainMenu_category>
</NewDataSet>

There are 3 joined SQL tables (home_category, product_category,
business_category, and admin_category) which all have a column named
category_name, but the XSD generated by the dataset renames these fields
to category_name, category_name1, category_name2. This makes sense since
these field needs to be correctly mapped to the appropriate menu_ID of
the parent SQL table called mainMenu_category.

But I don't like these names because my parser in my flash document
doesn't like them. They need to all be named "att0" and "att1". Like
this...

<NewDataSet>
<mainMenu_category att0="Home" att1="1">
<menu att1="1" />
</mainMenu_category> <mainMenu_category att0="Product" att1="2">
<menu att0="28.5 Volt DC Power Carts" att1="2" />
<menu att0="AC 400Hz. Power Carts" att1="2" />
<menu att0="Oxygen and Nitrogen Carts" att1="2" />
<menu att0="Tow Bars" att1="2" />
</mainMenu_category> <mainMenu_categoryatt0="Business Info" att1="3">
<menu att0="Contact Info" menu_ID="3" />
<menu att0="Email Us" menu_ID="3" />
<menu att0="Site Designed By..." att1="3" />
</mainMenu_category> <mainMenu_category att0="Admin" att1="4">
<menu att0="Sign In" att1="4" />
<menu att0="Sign Out" att1="4" />
<menu att0="Create New Account" att1="4" />
<menu att0="ManageAccounts" att1="4" />
<menu att0="Product Update" att1="4" />
<menuatt0="Contact Info Update" att1="4" />
<menu att0="List ServerUpdate" att1="4" />
</mainMenu_category>
</NewDataSet>

Here is the schema...

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="mainMenu_category">
<xs:complexType>
<xs:sequence>
<xs:element name="menu"
minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute
name="category_name" type="xs:string" />
<xs:attribute
name="category_name1" type="xs:string" />
<xs:attribute
name="category_name2" type="xs:string" />
<xs:attribute
name="menu_ID" type="xs:int" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="menu_name"
type="xs:string" />
<xs:attribute name="menu_ID"
type="xs:int" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//mainMenu_category" />
<xs:field xpath="@menu_ID" />
</xs:unique>
<xs:keyref name="custOrders" refer="Constraint1"
msdata:IsNested="true">
<xs:selector xpath=".//menu" />
<xs:field xpath="@menu_ID" />
</xs:keyref>
</xs:element>
</xs:schema>

Here is my C# code:
string sql1 = "SELECT menu_name, menu_ID";
sql1 += " FROM mainMenu_category";

string sql2 = "SELECT product_category.category_name,
business_category.category_name, admin_category.category_name,
menu.menu_ID";
sql2 += " FROM menu";
sql2 += " FULL JOIN product_category ON
(menu.product_category_ID = product_category.category_ID)";
sql2 += " FULL JOIN business_category ON
(menu.business_category_ID = business_category.category_ID)";
sql2 += " FULL JOIN admin_category ON
(menu.admin_category_ID = admin_category.category_ID)";
sql2 += " ORDER BY menu_ID,
product_category.category_order, business_category.category_order,
admin_category.category_order";

SqlConnection dataConn = new SqlConnection
(SQLconnStr);

dataConn.Open();

SqlDataAdapter sqlAdap1 = new SqlDataAdapter(sql1,
dataConn);
SqlDataAdapter sqlAdap2 = new SqlDataAdapter(sql2,
dataConn);

DataSet ds = new DataSet();
sqlAdap1.Fill(ds, "mainMenu_category");
sqlAdap2.Fill(ds, "menu");

dataConn.Close() ;

DataRelation rel = ds.Relations.Add("custOrders",
ds.Tables["mainMenu_category"].Columns["menu_ID"], ds.Tables
["menu"].Columns["menu_ID"]);
rel.Nested = true;

foreach ( DataTable dt in ds.Tables )
{
foreach ( DataColumn col in dt.Columns )
{
col.ColumnMapping = MappingType.Attribute;
}
}

ds.WriteXmlSchema(@"c:\myDS.xsd");
Response.Write(ds.GetXml());
So how do you change the attribute name "category_name" to attribute
name "att0"???

Thanks!

Nov 12 '05 #2
Isz

Haven't learned XSLT yet... can you point me to a good starter source...
I'll dig around in the mean time!

Thanks!
"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in news:#
$D*************@TK2MSFTNGP10.phx.gbl:
how about XSLT?

"Isz" <so*******@nowhere.net> wrote in message
news:UL********************@giganews.com...
Hi Group:

I would like to know if it is possible to change the name of an
attribute to something else. My setup is like this: I have serveral SQL tables that I nest and join so that it all outputs into a nice XML file for the purpose of populating a flash navigation menu.

<NewDataSet>
<mainMenu_category menu_name="Home" menu_ID="1">
<menu menu_ID="1" />
</mainMenu_category> <mainMenu_category menu_name="Product"
menu_ID="2">
<menu category_name="28.5 Volt DC Power Carts" menu_ID="2" /> <menu category_name="AC 400 Hz. Power Carts" menu_ID="2" /> <menu
category_name="Oxygen and Nitrogen Carts" menu_ID="2" /> <menu
category_name="Tow Bars" menu_ID="2" />
</mainMenu_category> <mainMenu_category menu_name="Business Info"
menu_ID="3">
<menu category_name1="Contact Info" menu_ID="3" /> <menu
category_name1="Email Us" menu_ID="3" /> <menu category_name1 ="Site Designed By..." menu_ID="3" />
</mainMenu_category> <mainMenu_category menu_name="Admin" menu_ID="4"> <menu category_name2="Sign In" menu_ID="4" /> <menu
category_name2="Sign Out" menu_ID="4" /> <menu
category_name2="Create New Account" menu_ID="4" /> <menu
category_name2="Manage Accounts" menu_ID="4" /> <menu
category_name2="Product Update" menu_ID="4" /> <menu
category_name2="Contact Info Update" menu_ID="4" /> <menu
category_name2="List Server Update" menu_ID="4" />
</mainMenu_category>
</NewDataSet>

There are 3 joined SQL tables (home_category, product_category,
business_category, and admin_category) which all have a column named
category_name, but the XSD generated by the dataset renames these fields to category_name, category_name1, category_name2. This makes sense since these field needs to be correctly mapped to the appropriate menu_ID of the parent SQL table called mainMenu_category.

But I don't like these names because my parser in my flash document
doesn't like them. They need to all be named "att0" and "att1". Like this...

<NewDataSet>
<mainMenu_category att0="Home" att1="1">
<menu att1="1" />
</mainMenu_category> <mainMenu_category att0="Product" att1="2">
<menu att0="28.5 Volt DC Power Carts" att1="2" />
<menu att0="AC 400Hz. Power Carts" att1="2" />
<menu att0="Oxygen and Nitrogen Carts" att1="2" />
<menu att0="Tow Bars" att1="2" />
</mainMenu_category> <mainMenu_categoryatt0="Business Info" att1 ="3"> <menu att0="Contact Info" menu_ID="3" />
<menu att0="Email Us" menu_ID="3" />
<menu att0="Site Designed By..." att1="3" />
</mainMenu_category> <mainMenu_category att0="Admin" att1="4">
<menu att0="Sign In" att1="4" />
<menu att0="Sign Out" att1="4" />
<menu att0="Create New Account" att1="4" />
<menu att0="ManageAccounts" att1="4" />
<menu att0="Product Update" att1="4" />
<menuatt0="Contact Info Update" att1="4" />
<menu att0="List ServerUpdate" att1="4" />
</mainMenu_category>
</NewDataSet>

Here is the schema...

<?xml version="1.0" standalone="yes" ?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas- microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="mainMenu_category">
<xs:complexType>
<xs:sequence>
<xs:element name="menu"
minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute
name="category_name" type="xs:string" />
<xs:attribute
name="category_name1" type="xs:string" />
<xs:attribute
name="category_name2" type="xs:string" />
<xs:attribute
name="menu_ID" type="xs:int" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="menu_name"
type="xs:string" />
<xs:attribute name="menu_ID"
type="xs:int" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//mainMenu_category" />
<xs:field xpath="@menu_ID" />
</xs:unique>
<xs:keyref name="custOrders" refer="Constraint1"
msdata:IsNested="true">
<xs:selector xpath=".//menu" />
<xs:field xpath="@menu_ID" />
</xs:keyref>
</xs:element>
</xs:schema>

Here is my C# code:
string sql1 = "SELECT menu_name, menu_ID";
sql1 += " FROM mainMenu_category";

string sql2 = "SELECT product_category.category_name,
business_category.category_name, admin_category.category_name,
menu.menu_ID";
sql2 += " FROM menu";
sql2 += " FULL JOIN product_category ON
(menu.product_category_ID = product_category.category_ID)";
sql2 += " FULL JOIN business_category ON
(menu.business_category_ID = business_category.category_ID)";
sql2 += " FULL JOIN admin_category ON
(menu.admin_category_ID = admin_category.category_ID)";
sql2 += " ORDER BY menu_ID,
product_category.category_order, business_category.category_order,
admin_category.category_order";

SqlConnection dataConn = new SqlConnection
(SQLconnStr);

dataConn.Open();

SqlDataAdapter sqlAdap1 = new SqlDataAdapter(sql1,
dataConn);
SqlDataAdapter sqlAdap2 = new SqlDataAdapter(sql2,
dataConn);

DataSet ds = new DataSet();
sqlAdap1.Fill(ds, "mainMenu_category");
sqlAdap2.Fill(ds, "menu");

dataConn.Close() ;

DataRelation rel = ds.Relations.Add("custOrders",
ds.Tables["mainMenu_category"].Columns["menu_ID"], ds.Tables
["menu"].Columns["menu_ID"]);
rel.Nested = true;

foreach ( DataTable dt in ds.Tables )
{
foreach ( DataColumn col in dt.Columns )
{
col.ColumnMapping = MappingType.Attribute;
}
}

ds.WriteXmlSchema(@"c:\myDS.xsd");
Response.Write(ds.GetXml());
So how do you change the attribute name "category_name" to attribute
name "att0"???

Thanks!



Nov 12 '05 #3

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

Similar topics

1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
2
by: maga1 | last post by:
I have a simple XML like this one: <a name="a"> <b> <c> 1 </c> </b> <b> <c>
15
by: Encapsulin | last post by:
Hello everybody. I'm trying to change src of quicktime embedded object with javascript: <html><body> <script language="JavaScript"> function Exchange() { document.qtvr.src = "sample2.pano";...
8
by: patrizio.trinchini | last post by:
Hi All, I'would like to write an XSL transformation that changes the value of the atribute of a given element according to the value of another atttribute of the same element. For instance,...
4
by: Hemal Pandya | last post by:
Hello, I am hoping this is a simple question with a straightforward solution. I do not understand xsl much, so I apologize in advance if I am asking a stupid question. Is it possible to write...
5
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am...
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
8
by: ismailc | last post by:
Hi, I would like to change the text color of (<xsl:value-of select="Description") onmouseover of image. the javascript works, it's just that i can seem to get the name correct <td>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.