By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,724 Members | 859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,724 IT Pros & Developers. It's quick & easy.

getting intellisense for custom XML

P: n/a
Don
Hi:
I have created an xsd from my xml document. I pop this xsd in the
following directory: C:\program files\Microsoft Visual Studio .NET
2003\Common7\Packages\schemas\xml. That give me intellisense when I specify
the name space. But leaving hte namespace in messes up my transforms.

Is there any way to get this intellisense functionality without adding the
namespace all the time?

Thanks,

Do
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Don" <do*************@hotmail.com> wrote in message news:Oq**************@TK2MSFTNGP09.phx.gbl...
That give me intellisense when I specify the name space.
But leaving hte namespace in messes up my transforms.

Is there any way to get this intellisense functionality without
adding the namespace all the time?


I don't believe there is. That would be very bad for me, if I
had XML schema documents in that folder to get Intelli-
Sense too, and no namespaces, and some of the elements
in my schema collided with names in your schema.

Since changing Microsoft's Visual Studio .NET is probably
a longshot, maybe we can have greater success changing
your transforms so they aren't screwed up by having a
namespace in them when you're doing transformations. :-)

Can you post some excerpts of your stylesheets and instance
documents where you're encountering these problems, and
then I or others in the newsgroup can suggest solutions to
make your transforms namespace-aware?
Derek Harmon
Nov 12 '05 #2

P: n/a
Don
Here is some code:
The xmlns="http://tempuri.org/formgenerator.xsd" is the namespace reference
I am talking about. I must add this to the root of the document to get
intellisense functionality. This file sits in C:\Program Files\Microsoft
Visual Studio .NET 2003\Common7\Packages\schemas\xml with all the other xsd
schemas used for intellisense.

If I leave that name space reference in the document, my document renders
incorrectly (see below). I must remove it in order to render correctly. So
it's an annoyance adding and removing this thing all the time just to get
some intellisense. As you mentioned, I should probably make all my
transformations "namespace aware"... and how do I do that in this case?

Thanks,

Don

---XML Code---
<?xml version="1.0" encoding="utf-8" ?>
<WEBFORM xmlns="http://tempuri.org/formgenerator.xsd"
templatename="iClas_form">
<SECTION VERSION="1" SName="form" WIDTH="646">
<SUBSECTION SName="form1">
<GROUP>
<INPUT VERSION="1" TYPE="Text" FName="1. Could I have your first name
please?" Name="FirstName"
XPath="/document/iClas_Contact[index='1']/Borrower/FirstName"
MAXLENGTH="15" SIZE="36"
DataType="String" ONCHANGE="" />
</GROUP>
</SUBSECTION>
</SECTION>
</WEBFORM>

---Resulting "View Source" from browser---
*Without the namespace reference* -- This is the incorrect one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="">
<form method="" name="" action="">
</form>
</xsl:template>
</xsl:stylesheet>

*With the namespace reference* --This is the correct one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="iClas_form"><link rel="stylesheet" type="text/css"
href="/CSS/corporate.css" /><script type="text/javascript"
src="/include/helper.js"></script></xsl:template>
</xsl:stylesheet>


"Derek Harmon" <lo*******@msn.com> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
"Don" <do*************@hotmail.com> wrote in message

news:Oq**************@TK2MSFTNGP09.phx.gbl...
That give me intellisense when I specify the name space.
But leaving hte namespace in messes up my transforms.

Is there any way to get this intellisense functionality without
adding the namespace all the time?


I don't believe there is. That would be very bad for me, if I
had XML schema documents in that folder to get Intelli-
Sense too, and no namespaces, and some of the elements
in my schema collided with names in your schema.

Since changing Microsoft's Visual Studio .NET is probably
a longshot, maybe we can have greater success changing
your transforms so they aren't screwed up by having a
namespace in them when you're doing transformations. :-)

Can you post some excerpts of your stylesheets and instance
documents where you're encountering these problems, and
then I or others in the newsgroup can suggest solutions to
make your transforms namespace-aware?
Derek Harmon

Nov 12 '05 #3

P: n/a
"Don" <do*************@hotmail.com> wrote in message news:O%****************@TK2MSFTNGP09.phx.gbl...
If I leave that name space reference in the document, my document renders
incorrectly (see below). I must remove it in order to render correctly. So
it's an annoyance adding and removing this thing all the time just to get
some intellisense. As you mentioned, I should probably make all my
transformations "namespace aware"... and how do I do that in this case?
You show two .xsl transformations. One looks 'empty' and you state
that's what gets created without a namespace declaration?

: : *Without the namespace reference* -- This is the incorrect one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="">
<form method="" name="" action="">
</form>
</xsl:template>
</xsl:stylesheet>
The other has content, although it has no main template, it doesn't
seem to depend on any XML node set, and I can't see how it's been
executed. This you've stated has a namespace declaration.

: : *With the namespace reference* --This is the correct one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="iClas_form"><link rel="stylesheet" type="text/css"
href="/CSS/corporate.css" /><script type="text/javascript"
src="/include/helper.js"></script></xsl:template>
</xsl:stylesheet>
If having the namespace declaration produces the correct
stylesheet, and produces IntelliSense from the schema, the
problem is what?

OK, let's look at the XML document.
<?xml version="1.0" encoding="utf-8" ?>
<WEBFORM xmlns="http://tempuri.org/formgenerator.xsd"
templatename="iClas_form">
<SECTION VERSION="1" SName="form" WIDTH="646">
<SUBSECTION SName="form1">
<GROUP>
<INPUT VERSION="1" TYPE="Text" FName="1. Could I have your first name
please?" Name="FirstName"
XPath="/document/iClas_Contact[index='1']/Borrower/FirstName"
MAXLENGTH="15" SIZE="36"
DataType="String" ONCHANGE="" />
</GROUP>
</SUBSECTION>
</SECTION>
</WEBFORM>


My guess is you're reading this XML in and generating the XSLT.
Whatever program is reading this takes the templatename attribute
value, iClas_form, and puts it into the stylesheet.

Now, if having the namespace URI declared is causing the template-
name attribute to not be found, then it's conceivable an empty name
attribute will be generated in the stylesheet.

What you have to do is change the code you're using to select that
attribute to respect the http://tempuri.org/formgenerator.xsd name-
space URI, because when there's a namespace declaration your
document doesn't contain a templatename attribute. Instead, it
contains a "http://tempuri.org/formgenerator.xsd:templatename"
attribute (which is distinguishable from the non-namespace
qualified "templatename").

You haven't shown the program code that's selecting the
templatename attribute, so I can't provide anymore details.
However, if you're using SelectNodes to use XPath to find
it, then you need to create an XmlNamespaceManager w/
a prefix associated with http://tempuri.org/formgenerator.xsd
and use that prefix in your XPath expression. Then use this
prefix-qualified XPath expression and the XmlNamespace-
Manager you created in the call to SelectNodes.

XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace("tns", "http://tempuri.org/formgenerator.xsd");
XmlNode templName = doc.SelectSingleNode(
"//tns:WEBFORM/@tns:templatename",
nsMan
);
Derek Harmon
Nov 12 '05 #4

P: n/a
Don
Derek:

I forgot to include the xsl template that is performing the transform.
This provides the two outputs (correct and incorrect) below.
I am not using any code. The XML and XSL documents are not manipulated at
all. I guess I just need some code to ignore or handle the namespace
reference at the root of the document. If I need to do something different,
let me know.

Thanks,

Do

Here it is:

<xsl:template match="/">
<xsl:element name="xsl:stylesheet">
<xsl:attribute name="version">1.0</xsl:attribute>
<xsl:element name="xsl:template">
<xsl:attribute name="name"><xsl:value-of select="/WEBFORM/@templatename"
/></xsl:attribute>
<xsl:if test="/WEBFORM/@CSS='1'">
<xsl:value-of disable-output-escaping="yes" select="/WEBFORM/CSSREF" />
<link rel="stylesheet" type="text/css" href="/CSS/corporate.css" />
</xsl:if>
<xsl:if test="/WEBFORM/@JS='1'">
<xsl:value-of disable-output-escaping="yes" select="/WEBFORM/JS" />
<script type="text/javascript" src="/include/helper.js"></script>
</xsl:if>
<xsl:choose>
<xsl:when test="/WEBFORM/@NOFORMTAG='1'">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<form>
<xsl:if test="/WEBFORM/@ONSUBMIT"><xsl:attribute
name="onsubmit"><xsl:value-of select="/WEBFORM/@ONSUBMIT"
/></xsl:attribute></xsl:if>
<xsl:attribute name="method"><xsl:value-of select="/WEBFORM/@method"
/></xsl:attribute><xsl:attribute name="name"><xsl:value-of
select="/WEBFORM/@name" /></xsl:attribute><xsl:attribute
name="action"><xsl:value-of select="/WEBFORM/@action" /></xsl:attribute>
<xsl:apply-templates />
</form>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:element>
</xsl:template>


"Derek Harmon" <lo*******@msn.com> wrote in message
news:Op**************@tk2msftngp13.phx.gbl...
"Don" <do*************@hotmail.com> wrote in message

news:O%****************@TK2MSFTNGP09.phx.gbl...
If I leave that name space reference in the document, my document renders incorrectly (see below). I must remove it in order to render correctly. So it's an annoyance adding and removing this thing all the time just to get some intellisense. As you mentioned, I should probably make all my
transformations "namespace aware"... and how do I do that in this case?


You show two .xsl transformations. One looks 'empty' and you state
that's what gets created without a namespace declaration?

: :
*Without the namespace reference* -- This is the incorrect one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="">
<form method="" name="" action="">
</form>
</xsl:template>
</xsl:stylesheet>


The other has content, although it has no main template, it doesn't
seem to depend on any XML node set, and I can't see how it's been
executed. This you've stated has a namespace declaration.

: :
*With the namespace reference* --This is the correct one
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="iClas_form"><link rel="stylesheet" type="text/css"
href="/CSS/corporate.css" /><script type="text/javascript"
src="/include/helper.js"></script></xsl:template>
</xsl:stylesheet>


If having the namespace declaration produces the correct
stylesheet, and produces IntelliSense from the schema, the
problem is what?

OK, let's look at the XML document.
<?xml version="1.0" encoding="utf-8" ?>
<WEBFORM xmlns="http://tempuri.org/formgenerator.xsd"
templatename="iClas_form">
<SECTION VERSION="1" SName="form" WIDTH="646">
<SUBSECTION SName="form1">
<GROUP>
<INPUT VERSION="1" TYPE="Text" FName="1. Could I have your first name please?" Name="FirstName"
XPath="/document/iClas_Contact[index='1']/Borrower/FirstName"
MAXLENGTH="15" SIZE="36"
DataType="String" ONCHANGE="" />
</GROUP>
</SUBSECTION>
</SECTION>
</WEBFORM>


My guess is you're reading this XML in and generating the XSLT.
Whatever program is reading this takes the templatename attribute
value, iClas_form, and puts it into the stylesheet.

Now, if having the namespace URI declared is causing the template-
name attribute to not be found, then it's conceivable an empty name
attribute will be generated in the stylesheet.

What you have to do is change the code you're using to select that
attribute to respect the http://tempuri.org/formgenerator.xsd name-
space URI, because when there's a namespace declaration your
document doesn't contain a templatename attribute. Instead, it
contains a "http://tempuri.org/formgenerator.xsd:templatename"
attribute (which is distinguishable from the non-namespace
qualified "templatename").

You haven't shown the program code that's selecting the
templatename attribute, so I can't provide anymore details.
However, if you're using SelectNodes to use XPath to find
it, then you need to create an XmlNamespaceManager w/
a prefix associated with http://tempuri.org/formgenerator.xsd
and use that prefix in your XPath expression. Then use this
prefix-qualified XPath expression and the XmlNamespace-
Manager you created in the call to SelectNodes.

XmlNamespaceManager nsMan = new XmlNamespaceManager( doc.NameTable);
nsMan.AddNamespace("tns", "http://tempuri.org/formgenerator.xsd");
XmlNode templName = doc.SelectSingleNode(
"//tns:WEBFORM/@tns:templatename",
nsMan
);
Derek Harmon

Nov 12 '05 #5

P: n/a
"Don" <do*************@hotmail.com> wrote in message news:uy**************@TK2MSFTNGP10.phx.gbl...
I forgot to include the xsl template that is performing the transform.
That addition definitely clears matters up. :-)
I guess I just need some code to ignore or handle the namespace
reference at the root of the document. If I need to do something
different, let me know.


Two very simple changes: add an xmlns declaration to the <xsl:stylesheet>
element of your primary XSLT transform that associates some prefix
with the namespace URI: http://tempuri.org/formgenerator.xsd.

Then, use this prefix for all elements in the template's XPath expressions
(it's not normally necessary to prefix the attributes, because attributes by
default will be unqualified, unless you're using an XML schema with an
attributeForm='qualified' on an <xsd:attribute> or attributeFormDefault=
'qualified' on the <xsd:schema>).

An optional third step is to use <xsl:element> for <form>, <link> and
<script> tags, otherwise you may get the XML namespace declaration
repeatedly showing up. I demonstrate this here.

Here's the fixed-up template (and xmlns on the <xsl:stylesheet>).

- - - nsAwareTransform.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://tempuri.org/formgenerator.xsd" >
<!--
. . .
-->
<xsl:template match="/">
<xsl:element name="xsl:stylesheet">
<xsl:attribute name="version">1.0</xsl:attribute>

<xsl:element name="xsl:template">
<xsl:attribute name="name">
<xsl:value-of select="/ns:WEBFORM/@templatename"/>
</xsl:attribute>
<xsl:if test="/ns:WEBFORM/@CSS='1'">
<xsl:value-of disable-output-escaping="yes"
select="/ns:WEBFORM/ns:CSSREF" />
<!-- <link rel="stylesheet" type="text/css" href="/CSS/corporate.css" /> -->
<xsl:element name="link">
<xsl:attribute name="rel">stylesheet</xsl:attribute>
<xsl:attribute name="type">text/css</xsl:attribute>
<xsl:attribute name="href">/CSS/corporate.css</xsl:attribute>
</xsl:element>
</xsl:if>

<xsl:if test="/ns:WEBFORM/@JS='1'">
<!-- <script type="text/javascript" src="/include/helper.js"></script> -->
<xsl:element name="script">
<xsl:attribute name="type">text/javascript</xsl:attribute>
<xsl:attribute name="src">/include/helper.js</xsl:attribute>
<xsl:value-of disable-output-escaping="yes"
select="/ns:WEBFORM/ns:JS" />
</xsl:element>
</xsl:if>

<xsl:choose>
<xsl:when test="/ns:WEBFORM/@NOFORMTAG='1'">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<xsl:element name="form">
<xsl:if test="/ns:WEBFORM/@ONSUBMIT">
<xsl:attribute name="onsubmit">
<xsl:value-of
select="/ns:WEBFORM/@ONSUBMIT"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="method">
<xsl:value-of
select="/ns:WEBFORM/@method"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of
select="/ns:WEBFORM/@name" />
</xsl:attribute>
<xsl:attribute name="action">
<xsl:value-of select="/ns:WEBFORM/@action" />
</xsl:attribute>
<xsl:apply-templates />
</xsl:element> <!-- end form -->
</xsl:otherwise>
</xsl:choose>

</xsl:element> <!-- end xsl:template -->
</xsl:element> <!-- end xsl:stylesheet -->

</xsl:template>
<!--
.. . .
-->
</xsl:stylesheet>
- - -

Notice how the ns namespace prefix is declared in the xsl:stylesheet
of this stylesheet, and then used as the prefix locating the elements in
your source XML document. This is what makes the stylesheet NS
aware.

When I added 3 attributes to your original example XML's WEBFORM
element (CSS="1", JS="1" and NOFORMTAG="1"), I was then able
to produce the same XSLT as you indicated in your correct example
using this stylesheet and Saxon.

If you have any other questions about how this works, just ask. :-)
Derek Harmon
Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.