Solved

Invalid character during XML transformation

Posted on 2007-12-06
3
270 Views
Last Modified: 2013-11-18
I have the following XML
<?xml version="1.0" encoding="UTF-8"?>
  <DataSet xmlns="http://tempuri.org/">
      <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" msdata:UseCurrentLocale="true">
          <xs:complexType>
              <xs:choice minOccurs="0" maxOccurs="unbounded">
                  <xs:element name="Table1">
                      <xs:complexType>
                          <xs:sequence>
                              <xs:element name="bfw_uid" type="xs:string" minOccurs="0" />
                              <xs:element name="Status" type="xs:int" minOccurs="0" />
                              <xs:element name="ExpirationDate" type="xs:dateTime" minOccurs="0" />
                          </xs:sequence>
                      </xs:complexType>
                  </xs:element>
              </xs:choice>
          </xs:complexType>
      </xs:element>
      </xs:schema>
      <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
          <NewDataSet xmlns="">
              <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fd6</bfw_uid>
                  <Status>1</Status>
                  <ExpirationDate>2008-12-05T00:00:00+05:30</ExpirationDate>
              </Table1>
              <Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">
                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdc</bfw_uid>
                  <Status>1</Status>
                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate>
              </Table1>
              <Table1 diffgr:id="Table13" msdata:rowOrder="2" diffgr:hasChanges="inserted">
                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdb</bfw_uid>
                  <Status>1</Status>
                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate>
              </Table1>
          </NewDataSet>
      </diffgr:diffgram>
  </DataSet>

I am transforming it to an XML using this XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:template match="NewDataSet" >
        <NewDataSet>
            <xsl:apply-templates />
        </NewDataSet>
    </xsl:template>
   
    <xsl:template match="Table1">
        <Table1>
        <xsl:apply-templates />
        </Table1>
    </xsl:template>
   
    <xsl:template match="bfw_uid">
        <bfw_uid>
            <xsl:value-of select="text()"></xsl:value-of>
        </bfw_uid>
    </xsl:template>
   
    <xsl:template match="Status">
        <Status>
            <xsl:value-of select="text()"></xsl:value-of>
        </Status>
    </xsl:template>
   
    <xsl:template match="ExpirationDate">
        <ExpirationDate>
            <xsl:value-of select="text()"></xsl:value-of>
        </ExpirationDate>
    </xsl:template>
   
</xsl:stylesheet>

But surprisingly the transformation gives a -(hyphen) as the first character. Can some one please tell me why that is happening. The output that I get is

<?xml version="1.0" encoding="UTF-8"?>

      - 

          

              

      

          <NewDataSet>

              <Table1>

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fd6</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T00:00:00+05:30</ExpirationDate> 

              </Table1>

              <Table1>

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdc</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate> 

              </Table1>

              <Table1>

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdb</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate> 

              </Table1>

          </NewDataSet>

Open in new window

0
Comment
Question by:thomas908
  • 2
3 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 20422145
You are generating it here:
...xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">- <xs:element name="NewDataSet" ...
0
 
LVL 82

Accepted Solution

by:
hielo earned 100 total points
ID: 20422157
Try this:
<?xml version="1.0" encoding="UTF-8"?>

  <DataSet xmlns="http://tempuri.org/">

      <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" msdata:UseCurrentLocale="true">

          <xs:complexType>

              <xs:choice minOccurs="0" maxOccurs="unbounded">

                  <xs:element name="Table1">

                      <xs:complexType>

                          <xs:sequence>

                              <xs:element name="bfw_uid" type="xs:string" minOccurs="0" /> 

                              <xs:element name="Status" type="xs:int" minOccurs="0" /> 

                              <xs:element name="ExpirationDate" type="xs:dateTime" minOccurs="0" /> 

                          </xs:sequence>

                      </xs:complexType>

                  </xs:element>

              </xs:choice>

          </xs:complexType>

      </xs:element>

      </xs:schema>

      <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

          <NewDataSet xmlns="">

              <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fd6</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T00:00:00+05:30</ExpirationDate> 

              </Table1>

              <Table1 diffgr:id="Table12" msdata:rowOrder="1" diffgr:hasChanges="inserted">

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdc</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate> 

              </Table1>

              <Table1 diffgr:id="Table13" msdata:rowOrder="2" diffgr:hasChanges="inserted">

                  <bfw_uid>c0a8cc3f:1def3f51166b4f90a6-7fdb</bfw_uid> 

                  <Status>1</Status> 

                  <ExpirationDate>2008-12-05T16:39:08+05:30</ExpirationDate> 

              </Table1>

          </NewDataSet>

      </diffgr:diffgram>

  </DataSet>

Open in new window

0
 
LVL 12

Assisted Solution

by:jkmyoung
jkmyoung earned 25 total points
ID: 20424093
You could create a root template to select the nodes that you process.
Eg, Add to your stylesheet:

<xsl:template match="/">

  <xsl:apply-templates select="//NewDataSet"/>

</xsl:template>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Magento Indexing 1 89
Help with SimpleXML charts with PHP 4 84
Problem to ToolkitScriptManager 2 51
Windows Tool to Build Android and iOS App 3 54
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now