boondocksaint20
Member
- Joined
- May 1, 2006
- Messages
- 6
- Programming Experience
- 3-5
Hello,
I have a vb.net application that pulls an xml from a webservice, then runs through code to write it to a database. The XML from the webservice does not print blank elements, so I've had to use an XSL stylesheet (included below) for the push to a SQL Server database to convert the XML to show blank elements (i.e. <element></element>).
This works in the code that I have, however, you have to manually paste the xsl link into the xml file each time you pull the xml from the webservice.
To combat this, I found code to transform the xml file to include the xsl file. By messing around, the following vb.net code compiles and runs, and the xml it outputs to the Console is well formed, however, it is missing ALL data from the xml file, so only the elements tags print out.
My experiment is as follows:
'Create the XslTransform.
Dim xslt as XslTransform = new XslTransform()
'Create a resolver and set the credentials to use.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials
'Load the stylesheet.
xslt.Load("UnitType.xsl", resolver)
'Load the XML data file.
Dim doc as XPathDocument = new XPathDocument("UnitType.xml")
'Create the XmlTextWriter to output to the console.
Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)
'Transform the file.
xslt.Transform(doc, nothing, writer, nothing)
writer.Close()
---------------------
The Console Output of the above code:
<UnitType><UIC></UIC><Name></Name><Type></Type></UnitType>...etc
Instead of what it should be:
<UnitType><UIC>C2000</UIC><Name>N33</Name><Type>type1</Type></UnitType>....etc
--------------------
Here is an example of my XML "UnitType.xml"
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfUnitType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlsns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UnitType>
<UIC xmlns="urn:ShipSchedules">C2000</UIC>
<Name xmlns="urn:ShipSchedules">N33</Name>
<Type xmlns="urn:ShipSchedules">type1</Type>
</UnitType>
<UnitType>
<UIC xmlns="urn:ShipSchedules">C2001</UIC>
<Type xmlns="urn:ShipSchedules">type2</Type>
</UnitType>
-------------------------
Here is my XSLT "UnitType.xsl"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="UnitType">
<UIC><xsl:value-of select="UIC"/></UIC>
<Name><xsl:value-of select="Name"/></Name>
<Type>><xsl:value-of select="Type"/></Type>
</xsl:template>
</xsl:stylesheet>
Now, my question is this, is the reason no data values in the elements is writing to the Console bc of my xslt or because of my vb code?
Thanks in advance!!
I have a vb.net application that pulls an xml from a webservice, then runs through code to write it to a database. The XML from the webservice does not print blank elements, so I've had to use an XSL stylesheet (included below) for the push to a SQL Server database to convert the XML to show blank elements (i.e. <element></element>).
This works in the code that I have, however, you have to manually paste the xsl link into the xml file each time you pull the xml from the webservice.
To combat this, I found code to transform the xml file to include the xsl file. By messing around, the following vb.net code compiles and runs, and the xml it outputs to the Console is well formed, however, it is missing ALL data from the xml file, so only the elements tags print out.
My experiment is as follows:
'Create the XslTransform.
Dim xslt as XslTransform = new XslTransform()
'Create a resolver and set the credentials to use.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = CredentialCache.DefaultCredentials
'Load the stylesheet.
xslt.Load("UnitType.xsl", resolver)
'Load the XML data file.
Dim doc as XPathDocument = new XPathDocument("UnitType.xml")
'Create the XmlTextWriter to output to the console.
Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)
'Transform the file.
xslt.Transform(doc, nothing, writer, nothing)
writer.Close()
---------------------
The Console Output of the above code:
<UnitType><UIC></UIC><Name></Name><Type></Type></UnitType>...etc
Instead of what it should be:
<UnitType><UIC>C2000</UIC><Name>N33</Name><Type>type1</Type></UnitType>....etc
--------------------
Here is an example of my XML "UnitType.xml"
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfUnitType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlsns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<UnitType>
<UIC xmlns="urn:ShipSchedules">C2000</UIC>
<Name xmlns="urn:ShipSchedules">N33</Name>
<Type xmlns="urn:ShipSchedules">type1</Type>
</UnitType>
<UnitType>
<UIC xmlns="urn:ShipSchedules">C2001</UIC>
<Type xmlns="urn:ShipSchedules">type2</Type>
</UnitType>
-------------------------
Here is my XSLT "UnitType.xsl"
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="UnitType">
<UIC><xsl:value-of select="UIC"/></UIC>
<Name><xsl:value-of select="Name"/></Name>
<Type>><xsl:value-of select="Type"/></Type>
</xsl:template>
</xsl:stylesheet>
Now, my question is this, is the reason no data values in the elements is writing to the Console bc of my xslt or because of my vb code?
Thanks in advance!!
