Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an XML from a dataset

Status
Not open for further replies.

ac11nyc

Programmer
Oct 1, 2003
94
US
I want to create and setup an XML from a dataset. How do you create an XML file programmatically so that the XML file can look the way i want it to look so that it loads into a template that is already created. Any point in the right direction would be great thanx
 
Basically you'd load the DataSet into an XmlDataDocument, then run an XSL transform on it.
 
i dont want the XML file to look like the dataset. I want to take the data from the dataset and create an XML in a certain way so that it loads into the template correctly otherwise it will not load correctly.
 
i dont want the XML file to look like the dataset."

That's why you'd run the XSL transform to get it into the format you want.
 
Let me clear this up:
I have a dataset that looks like this:

<NewDataSet xmlns="">
<FC_PROFILE diffgr:id="FC_PROFILE1" msdata:rowOrder="0">
<FCName>Steve Smith</FCName>
<FCSiteName>SSmith</FCSiteName>
<GroupName>Private Client Group</GroupName>
<FCPhoto>SSmith.gif</FCPhoto>
</FC_PROFILE>
</NewDataSet>

I need the XML to be transformed into:

<FC_WEB_PROFILE xmlns=" <FC>
<FCName>Steve Smith</FCName>
<FCSiteName>SSmith</FCSiteName>
<GroupName>Private Client Group</GroupName>
<FCPhoto href="SSmith.gif"/>
</FC>
</FC_WEB_PROFILE>

Does anyone have a detailed clue on how to convert the datasets XML into the second version. I need this done so that i may load the XML into a stylesheet.
 
About conversion:

Untested (Probably Non-Functional) XML-to-XML Sample Sheet
Code:
<?xml version="1.0"?>
<!--<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/TR/WD-[/URL]
xsl" version="1.0">-->
<xsl:stylesheet
xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] version="1.0">

  <FC_WEB_PROFILE> 
    <xsl:template match="/">
      <xsl:for-each select="NewDataSet/FC_PROFILE">
        <FCName>
           <xsl:value-of select="FCName"/>
        </FCName>
        <!-- etc. -->
       </xsl:for-each>
    </xsl:template>
  </FC_WEB_PROFILE
</xsl:stylesheet>
 
Trying to use:
private const String filename="MyTable.xml";
private const String stylesheet="FCWebProfile.xsl";

private void Page_Load(object sender, System.EventArgs e)
{
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new
XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting=Formatting.Indented;

xslt.Transform(xpathdocument,null,writer,null);
}

PROBLEM:
It keeps telling me to use the namespace:
" - what does that mean and what if i already have it under the xlmns:xls
 
ok i need some more help with this:
Schema looks like:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="FCWebProfile" targetNamespace=" elementFormDefault="qualified"
xmlns=" xmlns:mstns=" xmlns:xs=" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Document">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="FC_WEB_PROFILE">
<xs:complexType>
<xs:sequence>
<xs:element name="EmployeeId" msdata:DataType="System.Guid, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
type="xs:string" />
<xs:element name="FCName" type="xs:string" />
<xs:element name="FCSiteName" type="xs:string" minOccurs="0" />
<xs:element name="GroupName" type="xs:string" minOccurs="0" />
<xs:element name="Title" type="xs:string" minOccurs="0" />
<xs:element name="EmailAddress" type="xs:string" minOccurs="0" />
<xs:element name="PhoneNumber" type="xs:string" minOccurs="0" />
<xs:element name="PhoneNumber2" type="xs:string" minOccurs="0" />
<xs:element name="FaxNumber" type="xs:string" minOccurs="0" />
<xs:element name="BranchName" type="xs:string" minOccurs="0" />
<xs:element name="BranchAddress1" type="xs:string" minOccurs="0" />
<xs:element name="BranchAddress2" type="xs:string" minOccurs="0" />
<xs:element name="BranchCity" type="xs:string" minOccurs="0" />
<xs:element name="BranchState" type="xs:string" minOccurs="0" />
<xs:element name="BranchZip" type="xs:string" minOccurs="0" />
<xs:element name="MissionStatement" type="xs:string" minOccurs="0" />
<xs:element name="BusinessExperience" type="xs:string" minOccurs="0" />
<xs:element name="Associations" type="xs:string" minOccurs="0" />
<xs:element name="Recognitions" type="xs:string" minOccurs="0" />
<xs:element name="Education" type="xs:string" minOccurs="0" />
<xs:element name="AreasOfConcentration" type="xs:string" minOccurs="0" />
<xs:element name="AdministrativeStaff" type="xs:string" minOccurs="0" />
<xs:element name="RegisteredStates" type="xs:string" minOccurs="0" />
<xs:element name="StatusCode" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="DocumentKey1" msdata:primaryKey="true">
<xs:selector xpath=".//mstns:FC_WEB_PROFILE" />
<xs:field xpath="mstns:EmployeeId" />
</xs:unique>
</xs:element>
</xs:schema>


MyTable XML looks like this:
<?xml version="1.0" standalone="yes"?>
<DOCUMENT>
<FC_WEB_PROFILE>
<EmployeeId>63645ebc-ade5-4393-a9e7-dedf987a8c79</EmployeeId>
<FCName>Daniel Ramer</FCName>
<FCSiteName>Danny</FCSiteName>
<GroupName>PCG Group - Florham Park</GroupName>
<Title>SENIOR VICE PRESIDENT</Title>
<EmailAddress>Daniel.Ramer@RyanBeck.com</EmailAddress>
<PhoneNumber>800.325.2325</PhoneNumber>
<PhoneNumber2>973.135.4135</PhoneNumber2>
<FaxNumber />
<BranchName>Florham Park</BranchName>
<BranchAddress1>18 Columbia Turnpike</BranchAddress1>
<BranchAddress2 />
<BranchCity>Florham Park</BranchCity>
<BranchState>NJ</BranchState>
<BranchZip>07932</BranchZip>
<MissionStatement>Ramer's philosophy is simple - analyze every aspect of a client's current financial situation and generate solutions to improve overall portfolio performance and preserve a comfortable lifestyle.</MissionStatement>
<BusinessExperience>16 years of experience with some of the industry's most respected brokerage firms.</BusinessExperience>
<Associations />
<Recognitions />
<Education>Registered with the National Association of Security Dealers. </Education>
<AreasOfConcentration>Ramer's extensive experience in the financial services industry gives him the background to service a wide variety of clients.</AreasOfConcentration>
<AdministrativeStaff>Andres Cano</AdministrativeStaff>
<RegisteredStates>NY, NJ</RegisteredStates>
<StatusCode>C</StatusCode>
</FC_WEB_PROFILE>
</DOCUMENT>

Why is that when i try to assign thw working XML file to the stylesheet, it no longer is part of the Document Root for the stylesheet. It now moves down into the Gloable templates. I have been having a big problem with this and cannot get this to work. If this isnt working then i cannot transform the documents so that i may use it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top