XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
- Stylus Studio Technical Forum (14621)
-> - Stylus Studio - Registrar en o... (1)
-> + Stylus Studio - Registrar en o... (2)
-> + Can a pipeline send a file by ... (2)
-> + After Updateing WIN10 to WIN11... (12)
-> + Where do I add the custom java... (3)
-> + Where is the Diagram tab? (5)
-> + Applying XSLT to Word DOCX/XML (2)
-> - CSV conversion via ConvertToXM... (1)
-> + Text symbols in SS not same as... (4)
-> + Exposing xquery as webservice ... (6)
-> + Syntax Identifier (2)
-> + Saving a Converted XML as an X... (5)
-> + Output document cannot be pars... (4)
-> - Archiving output from conversi... (1)
-> + EDIFACT guideline from Stylus ... (3)
-> + CSV file putting all the data ... (5)
-> + Can't install Home version 64b... (5)
-> + presale - Can I covers this sc... (5)
-> + Problem with UNB (5)
-> + Splitting EDIFACT files pipeli... (4)
-- [1-20] [21-40] [41-60] Next
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Yama KamyarSubject: Accessing a Dataset
Author: Yama Kamyar
Date: 21 Mar 2005 07:08 PM
Hello,

I have the following XML (ADO like) data:

<?xml version="1.0" encoding="UTF-16"?>
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
<s:AttributeType name="CustomerID" rs:number="1" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="5" rs:fixedlength="true" rs:maybenull="false" /></s:AttributeType><s:AttributeType name="CompanyName" rs:number="2" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="40" rs:maybenull="false" /></s:AttributeType><s:AttributeType name="ContactName" rs:number="3" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="30" /></s:AttributeType><s:AttributeType name="ContactTitle" rs:number="4" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="30" /></s:AttributeType><s:AttributeType name="Address" rs:number="5" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="60" /></s:AttributeType><s:AttributeType name="City" rs:number="6" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="15" /></s:AttributeType><s:AttributeType name="Region" rs:number="7" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="15" /></s:AttributeType><s:AttributeType name="PostalCode" rs:number="8" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="10" /></s:AttributeType><s:AttributeType name="Country" rs:number="9" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="15" /></s:AttributeType><s:AttributeType name="Phone" rs:number="10" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="24" /></s:AttributeType><s:AttributeType name="Fax" rs:number="11" rs:nullable="true" rs:writeunknown="true"><s:datatype dt:type="string" dt:maxLength="24" /></s:AttributeType><s:extends type="rs:rowbase" /></s:ElementType></s:Schema><rs:data><z:row CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" ContactName="Maria Anders" ContactTitle="Sales Representative" Address="Obere Str. 57" City="Berlin" PostalCode="12209" Country="Germany" Phone="030-0074321" Fax="030-0076545" /><z:row CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" ContactName="Ana Trujillo" ContactTitle="Owner" Address="Avda. de la Constitución 2222" City="México D.F." PostalCode="05021" Country="Mexico" Phone="(5) 555-4729" Fax="(5) 555-3745" /></rs:data></xml>

Here is some code I use to load the data into a dataset:

XmlTextReader xmlReader = new XmlTextReader(stream);
XmlDocument _doc = new XmlDocument();
XslTransform _transform = new XslTransform();
_doc.Load(xmlReader);
DataSet ds = new DataSet();
ds.ReadXml(stream, XmlReadMode.InferSchema);
ds.Namespace = "#RowsetSchema";

When I use ds.GetXml(); I get the following:
<xml xmlns="#RowsetSchema">
<rs:data xmlns:rs="urn:schemas-microsoft-com:rowset">
<z:row CustomerID="ALFKI" CompanyName="Alfreds Futterkiste" ContactName="Maria Anders" ContactTitle="Sales Representative" Address="Obere Str. 57" City="Berlin" PostalCode="12209" Country="Germany" Phone="030-0074321" Fax="030-0076545" xmlns:z="#RowsetSchema" />
<z:row CustomerID="ANATR" CompanyName="Ana Trujillo Emparedados y helados" ContactName="Ana Trujillo" ContactTitle="Owner" Address="Avda. de la Constitución 2222" City="México D.F." PostalCode="05021" Country="Mexico" Phone="(5) 555-4729" Fax="(5) 555-3745" xmlns:z="#RowsetSchema" />
</rs:data>
</xml>

Everything is great and all but I can't seem to access the columns. I would like to format some column names (i.e. "ContactName" to "Contact Name"). Also I would like to append or format some values for example change every instance PostalCode to include an additional "-0000" at the end.

Any clues?

Thanks,

~yamazed

Postnext
Ivan PedruzziSubject: Accessing a Dataset
Author: Ivan Pedruzzi
Date: 24 Mar 2005 12:02 AM
Yamazed,


Out of curiosity is the stream object pointing to an XML file?
If yes why are you using a DataSet and not just load the file into an XmlDocument object?

XML element name and attribute name can't contain space.


Ivan

Postnext
Yama KamyarSubject: Accessing a Dataset
Author: Yama Kamyar
Date: 24 Mar 2005 03:51 AM
Hi,

I resolve this issue but I get an output XML with that freaking hex _x0020_ for space! Now trying to figure out the best way to parse it.

Thanks,

~yamazed

Posttop
Yama KamyarSubject: Accessing a Dataset
Author: Yama Kamyar
Date: 24 Mar 2005 12:31 PM
Hi,

For those of you interested here is how I accessed the loaded dataset using ds.ReadXml(stream, XmlReadMode.InferSchema).

/// <summary>
/// Format Dataset:
/// Format Column names where necessary
/// <remark>
/// could retrieve from a config file then loop
/// through and change column names
/// </remark>
/// Convert, parse, or map the row to appropriate values
/// </summary>
/// <param name="ds">
/// ds.ReadXml(stream, XmlReadMode.InferSchema)
/// stream = well formed XML data in MemoryStream
/// </param>
private void PrintValues(DataSet ds)
{
Debug.Write("\r\n" + "TableName: ");
foreach(DataTable dt in ds.Tables)
{
Debug.Write("TableName: " + dt.TableName);
foreach(DataRow dr in dt.Rows)
{
foreach(DataColumn dc in dt.Columns)
{
switch(dc.ColumnName)
{
case "ColumnName1":
dc.ColumnName = "Column Name 1";
break;
case "ColumnName2":
dc.ColumnName = "Column Name 2";
Convert.ToInt64(dr[dc]));
break;
// etc...
}
Debug.Write("\t " + dc.ColumnName + ": " + dr[dc]);
}
Debug.WriteLine("");
ds.AcceptChanges();
}
}
}


Yama

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.