<employees>
  <employee>
    <user_id>6</user_id>
    <profile_name>Developer</profile_name>
    <profile_id>2</profile_id>
    <user_status>1</user_status>
    <gender>1</gender>
    <first_name>Anulesh</first_name>
    <last_name>Gupta</last_name>
    <address>106/B, 1st Floor, 46th Cross, 4th Block,  Rajajinagar,</address>
    <pswd>password</pswd>
    <pswd_change_dte>2011-01-25T19:48:00+05:30</pswd_change_dte>
    <email_addr>anulesh.gupta@effone.com</email_addr>
    <phone>91-080-22445281</phone>
    <dob>1981-09-18T00:00:00+05:30</dob>
    <join_date>2008-11-20T00:00:00+05:30</join_date>
    <receive_email_notification>true</receive_email_notification>
    <last_logged_in>2011-01-25T19:48:00+05:30</last_logged_in>
    <emp_id>1001</emp_id>
    <full_name>Anulesh Gupta</full_name>
    <skill_set />
    <city>Bangalore</city>
    <state>Karnataka</state>
    <country>India</country>
    <zip_code>560010</zip_code>
    <mobile_number>22445281</mobile_number>
    <pwd_flag>1</pwd_flag>
    <reports_to>5</reports_to>
  </employee>
 </employees>

Convert this into this format , please help me out for the same

<?xml version="1.0" encoding="utf-8" ?>
<employees>
	<employee firstname="Guy" lastname="Gilbert" title="Production Technician - WC60" emailaddress="guy1@adventure-works.com" phone="320-555-0195" />
</employees>

Recommended Answers

All 4 Replies

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml"/>
	<xsl:template match="/">
		<employees>
			<xsl:apply-templates select="employees"/>
		</employees>
	</xsl:template>
	<xsl:template match="employees">
		<xsl:apply-templates select="employee"/>
	</xsl:template>
	<xsl:template match="employee">
		<employee>
                        <!-- here your choice -->
			<xsl:attribute name="firstname">
				<xsl:value-of select="first_name"/>
			</xsl:attribute>
			<xsl:attribute name="lastname">
				<xsl:value-of select="last_name"/>
			</xsl:attribute>
			<xsl:attribute name="title">
				<xsl:value-of select="profile_name"/>
			</xsl:attribute>
			<xsl:attribute name="emailaddress">
				<xsl:value-of select="email_addr"/>
			</xsl:attribute>
			<xsl:attribute name="phone">
				<xsl:value-of select="phone"/>
			</xsl:attribute>
		</employee>
	</xsl:template>
</xsl:stylesheet>

Thanks XML Looser,
I already get the Output.

XDocument xml = XDocument.Parse(ds.GetXml());

            StringBuilder strXML = new StringBuilder();

            strXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><employees>");
            foreach (XElement element in xml.Descendants("employee"))
            {
                strXML.Append("<employee ");
                foreach (XElement ele in element.Elements())
                {
                    strXML.Append(" " + ele.Name.LocalName + "=\"" + ele.Value + "\" ");
                }
                strXML.Append(" />");
            }

            strXML.Append("</employees>");
XDocument xml = XDocument.Parse(ds.GetXml());

            StringBuilder strXML = new StringBuilder();

            strXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><employees>");
            foreach (XElement element in xml.Descendants("employee"))
            {
                strXML.Append("<employee ");
                foreach (XElement ele in element.Elements())
                {
                    strXML.Append(" " + ele.Name.LocalName + "=\"" + ele.Value + "\" ");
                }
                strXML.Append(" />");
            }

            strXML.Append("</employees>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.