473,573 Members | 5,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ID / IDREFS problem MSXML vs. System.XML

Hi all.

Does id() xpath function work in System.XML? I have built dtd, schema, xdr
for a simple xml which includes attributes definded as ID and IDREFS.
Validation is occurring properly for all the types of metadata, but the id()
function applied to the IDREFS attribute allways returns nothing.

I have tried it from xslt and using the XmlNode.selectn odes or
XPathNavigator. Select
nada zilch

The same code works using MSXML 3.0 and 4.0 class COM objects. I am getting
to the point of wanting to import them into .Net ( I know it is not supposed
to work that way but the code works.) I have also researched and learned
that XPath standard came before schema standard and that the different
development teams at MS have interpreted a little differently on what goes
in.

If anyone can point me to any samples that actually work with System.XML
using ID/IDREFS and XPath:id() would be greatly appreciated.

Thanks
Bill E


Nov 12 '05 #1
7 4234
Microsoft News wrote:
Does id() xpath function work in System.XML? I have built dtd, schema, xdr
for a simple xml which includes attributes definded as ID and IDREFS.


It does work, but requires attribute to be defined as ID in DTD, not
schema. There is some trick to get it working with schema too though.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Thanks for answering Oleg,

(I changed Outlook Express account to me not generic MS News)

I have a valid dtd which is used in validation via XMLValidatingRe ader and
it does pick up mistakes
( To test it I broke it a couple of different ways and it was allways
detected. )

Still can't get XPathNavigator. Select or XmlNode.SelectN odes to work with
XPATH id() function.

I saw your stuff on deriving from validating reader, I haven't tried that
with the XSD version yet and will shortly

Thanks again
Bill E.
Nov 12 '05 #3
Bill Eidson wrote:
I have a valid dtd which is used in validation via XMLValidatingRe ader and
it does pick up mistakes
( To test it I broke it a couple of different ways and it was allways
detected. )

Still can't get XPathNavigator. Select or XmlNode.SelectN odes to work with
XPATH id() function.


Well, should work. Make sure you are building XmlDocument or
XPathDocument via XmlValidatingRe ader. Or show us your code.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
The XML

=============== =============== =============== =============== =============== =
===============
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE workflow SYSTEM "http://localhost/xml/WorkflowProcess .dtd">
<!--
<workflow xmlns="http://localhost/xml"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocat ion="http://localhost/xml
http://localhost/xml/WorkflowProcess .xsd">
-->
<workflow xmlns="http://localhost/xml">
<Processes>
<Process processId="Welc omeEmail" errorProcessID= "timeouterr or"
type="email">
<Email>
<To firstName="Bob" lastName="James " occupation="Pia nist"
mailto="bj****@ music.org" />
<From mailto="ad***@a mazon.com" />
<EmailBody templateRef="We lcomeEmailTempl ate" />
</Email>
</Process>

<Process processId="Welc omePage" type="aspxPage" >
<Url href="welcome.a spx" />
</Process>

<Process processId="Emai lTimeout" errorProcessID= "timeouterr or"
type="email">
<Email>
<To mailto="ad***@m usic.org" />
<From mailto="ad***@a mazon.com" />
<EmailBody templateRef="Er rorEmailTemplat e" />
</Email>
</Process>

<Process processId="End" type="end">
<End />
</Process>
</Processes>

<Flows>
<Flow flowID="normal" processIDs="Wel comeEmail WelcomePage End" />
<Flow flowID="timeout error" processIDs="Ema ilTimeout End" />
</Flows>

<Templates>
<Template templateID="Wel comeEmailTempla te"
href="file://c:emailtemplate .xslt" />
<Template templateID="Err orEmailTemplate "
href="file://c:emailtemplate .xslt" />
</Templates>
</workflow>
=============== =============== =============== =============== =============== =
=============== =======

DTD

<!ELEMENT workflow (Processes, Flows, Templates)>
<!ATTLIST workflow
xmlns CDATA #IMPLIED>

<!ELEMENT Processes (Process)*>

<!ELEMENT Process ( Email | Url | Start | End )>
<!ATTLIST Process
processId ID #REQUIRED
type ( email | aspxPage | end ) #REQUIRED
errorProcessID IDREF #IMPLIED >

<!ELEMENT Start EMPTY>
<!ELEMENT End EMPTY>
<!ELEMENT Url EMPTY>
<!ATTLIST Url href CDATA #REQUIRED>

<!ELEMENT Email (To, From, EmailBody )>

<!ELEMENT To EMPTY>
<!ATTLIST To
firstName CDATA #IMPLIED
lastName CDATA #IMPLIED
occupation CDATA #IMPLIED
mailto CDATA #REQUIRED>

<!ELEMENT From EMPTY>
<!ATTLIST From
firstName CDATA #IMPLIED
lastName CDATA #IMPLIED
occupation CDATA #IMPLIED
mailto CDATA #REQUIRED>

<!ELEMENT EmailBody EMPTY>
<!ATTLIST EmailBody
templateRef IDREF #REQUIRED>

<!ELEMENT Flows (Flow)*>

<!ELEMENT Flow EMPTY>
<!ATTLIST Flow
flowID ID #REQUIRED
processIDs IDREFS #REQUIRED>

<!ELEMENT Templates (Template)*>

<!ELEMENT Template EMPTY>
<!ATTLIST Template
templateID ID #REQUIRED
href CDATA #REQUIRED>

=============== =============== =============== =============== ==============

C# Code Version

try
{
System.Diagnost ics.Debug.Write Line( "Schema Collection Add..." );
XmlSchemaCollec tion sc = new XmlSchemaCollec tion();
sc.ValidationEv entHandler += new
ValidationEvent Handler(HandleV alidationEvents );
// sc.Add( "http://localhost/xml", dtd );

XmlDocument ex = new XmlDocument();
XmlTextReader tr = new XmlTextReader( "file://" + emailXML );
XmlValidatingRe ader vXR = new XmlValidatingRe ader(tr);

vXR.ValidationT ype = ValidationType. Auto;
vXR.ValidationE ventHandler += new
ValidationEvent Handler(HandleV alidationEvents );
vXR.Schemas.Add (sc);

System.Diagnost ics.Debug.Write Line( "Loading ..." );
ex.Load(vXR);

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager( ex.NameTable );
nsmgr.AddNamesp ace( "x", "http://localhost/xml" );
nsmgr.AddNamesp ace( "xs", "http://www.w3.org/2001/XMLSchema" );
XPathNavigator nav = ex.CreateNaviga tor();

// XmlNodeList nl =
ex.DocumentElem ent.SelectNodes ("id(//x:Flow[@flowID='normal ']/@processIDs)",
nsmgr);
XPathNodeIterat or nl = nav.Select("id( 'WelcomeEmail') " );
while( nl.MoveNext() )
{
txtResults.Text += nl.Current.Name
txtResults.Text += "\r\n";
}

XslTransform xsl = new XslTransform();
xsl.Load( "file://" + emailTemplate );

XmlDocument resX = new XmlDocument();
XsltArgumentLis t al = new XsltArgumentLis t();
resX.Load( xsl.Transform( nav,al ));

System.IO.Strin gWriter s = new System.IO.Strin gWriter();
XmlTextWriter tw = new XmlTextWriter(s );
tw.Formatting = Formatting.Inde nted;
tw.Indentation = 2;
resX.WriteTo( tw );
txtResults.Text += s.ToString();
}
catch ( System.Xml.XmlE xception xe )
{
System.Diagnost ics.Debug.Write ( xe.ToString() + "\r\n" );
}

I have tried various combinations of the Selection functions all
unsuccessful.

=============== =============== =============== =============== =============== =
===========
XSLT

<?xml version="1.0" ?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:x="http://localhost/xml" >

<xsl:output method="xml" indent="yes" />
<xsl:template match="/" >
<h:html>
<h:body>
<xsl:for-each select="x:Flows/x:Flow" >
<h:li><xsl:valu e-of select="." /></h:li>
</xsl:for-each>
<xsl:apply-templates select="*" />
</h:body>
</h:html>
</xsl:template>

<xsl:template match="x:Flow">
<h:li>Found Flow match <xsl:value-of select="@proces sIDs" /></h:li>
<xsl:for-each select="id('@pr ocessIDs')" >
<xsl:value-of select="." />
</xsl:for-each>
<h:p>how many did we find</h:p>
</xsl:template>

</xsl:stylesheet>

The stylesheet matches the Flow elements finds the @processIDs attributes
but the id function doesn't do anything.
=============== =============== =============== =============== =============== =
==========

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:ep******** ******@tk2msftn gp13.phx.gbl...
Bill Eidson wrote:
I have a valid dtd which is used in validation via XMLValidatingRe ader and it does pick up mistakes
( To test it I broke it a couple of different ways and it was allways
detected. )

Still can't get XPathNavigator. Select or XmlNode.SelectN odes to work with XPATH id() function.


Well, should work. Make sure you are building XmlDocument or
XPathDocument via XmlValidatingRe ader. Or show us your code.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #5
Bill Eidson wrote:
The stylesheet matches the Flow elements finds the @processIDs attributes
but the id function doesn't do anything.


Well, after more investigation now I see. It really doesn't work. I've
found 2 bugs involved.

First of all small but annoying bug - seems like id() function is unable
to convert its argument to string as it should per XSLT spec. So instead
of id(@processIDs) one should use id(string(@proc essIDs)).

Second one - it looks like XmlDocument is unable to cope with IDs when
namespaces involved. If you took default namespace declaration from your
XML, then id() function works, but not with namespace. Somehow
XmlDocument doesn't think elements in a namespace as eligible to be
referenced by ID. I didn't trace the problem though. Just use
XPathDocument instead, DOM is dead anyway :)

So, to make your code working use XPathDocument instead of XmlDocument
and convert id() function's argument to string explicitly via string()
function.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #6
Hey Oleg, Thanks

The dtd version works hip hip hooray.
Both xslt and code version are happy campers.

This subtle bug in id function is a bit rude.

What did you mean by the DOM is dead... Is the model deprecated ?

Thanks again

bille

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:ev******** ********@TK2MSF TNGP09.phx.gbl. ..
Bill Eidson wrote:
The stylesheet matches the Flow elements finds the @processIDs attributes but the id function doesn't do anything.


Well, after more investigation now I see. It really doesn't work. I've
found 2 bugs involved.

First of all small but annoying bug - seems like id() function is unable
to convert its argument to string as it should per XSLT spec. So instead
of id(@processIDs) one should use id(string(@proc essIDs)).

Second one - it looks like XmlDocument is unable to cope with IDs when
namespaces involved. If you took default namespace declaration from your
XML, then id() function works, but not with namespace. Somehow
XmlDocument doesn't think elements in a namespace as eligible to be
referenced by ID. I didn't trace the problem though. Just use
XPathDocument instead, DOM is dead anyway :)

So, to make your code working use XPathDocument instead of XmlDocument
and convert id() function's argument to string explicitly via string()
function.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #7
Bill Eidson wrote:
What did you mean by the DOM is dead... Is the model deprecated ?


That has been claimed by Mark Fussel in his ".NET Framework: What's New
in System.Xml for "Whidbey" session at PDC. See
http://www.25hoursaday.com/weblog/Pe...1-362b0a896f08
That doesn't mean XmlDocument is deprecated. It will be fully supported,
but the main focus is going to be XPathDocument (which is editable in
the next version), becuse it's more clean, robust, effective and better
fits XQuery data model.
Mark explained that at great length in microsoft.priva te.whidbey.xml
newsgroup
(http://communities.microsoft.com/new...dbey&slcid=us).
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1973
by: Rabe | last post by:
Hi all, here a little brain-twister (starting to spoil my weekend if I do not find a solution ... ;-) ) What I want to do is to find a XML-Schema expression that builds a grammar for the following XML document (fragment): <grouping_document> <app_list>
5
5412
by: Stuart Robertson | last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object. The XML I'm trying to produce is as...
2
3524
by: Keith Chadwick | last post by:
I am current in the process of converting an existing ASP application to ASP.NET. The existing application makes extensive use of server side XML transformations as in rslt=myxmlobj.tranform(myxsltdoc). Now I have included the reference to the MSXML 3.0 object into my .NET application and have it working but I am wondering am I better off...
19
4802
by: Mark Miller | last post by:
QUESTION: Does anyone know how I can use v2.6 of the MSXML parser with .NET? BACKGROUND: I "Web to Print" process that allows our clients (newspapers) to export their data and pass it thru a custom Xslt stylesheet we have created for their print system. The idea of the whole process for them is they request the export and then they get a...
3
3630
by: Eugen Gulinsky | last post by:
Hello guys, I am having problems trying to migrate our MSXML4-compatible stylesheets containing large msxsl:script blocks to a formate understandable by System.Xml:Xsl.XslTransform. I keep getting JS1135 errors saying that some variable was not declared. This scripts worked perfectly with MSXML4. Is there a guide for migraiton from MSXML to...
4
6888
by: K | last post by:
I've an XML file in UTF-8. It contains some chinese characters ( both simplified chinese and traditional chinese). In loading the XML file with MSXML parser, I used the below code to retrieve the data in a node. The CString was then display in CListCtrl. For the traditional chinese characters, they were shown correctly, but for simplified...
6
1499
by: Mark | last post by:
In a specification I'm designing, I'd like to specify that the order of Names (IDs) in an attribute value of datatype IDREFS is significant. My question is if most real-world XML parsers preserve the order of IDs in IDREFS? If most don't, then specifying the significance of order is problematic. (As far as I can tell, the XML 1.0 spec is...
19
2588
by: Matthias Truxa | last post by:
Hello, can anyone confirm the existence of the following effects which I'd consider being a critical bug in msxml according to w3c's xpath specs? The Spec says: "The parent, ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes" http://www.w3.org/TR/2005/CR-xpath20-20051103/#doc-xpath-ReverseAxis
4
11814
by: mrjaxon | last post by:
I have a C# web application which leverages MSXML that I am trying to migrate to a 64 bit environment. Currently the application is built on the .NET 2.0 Framework and using MSXML 6 (though I had the same issues using version 4). The OS I am running the app on is Windows Server 2003 x64. I am using the x64 version of MSXML 6 on the server....
0
7789
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3737
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2227
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1325
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.