Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Processing IDRefs DOMDocument

From: "Robert Rolls" <implatform@--------.---.-->
To: NULL
Date: 7/5/2005 7:18:00 AM
I've got an xml schema document that describes how the instance documents 
are layed out - can I only use a DTD to get ID/IDREF/IDREFS to work?

Thanks.
Robert.

"Martin Honnen" <mahotrash@y...> wrote in message 
news:%23vf$nwJgFHA.3656@T......
>
>
> Robert Rolls wrote:
>
>
>> I have some xml that has an IDREFs type holding multiple IDs how do I get 
>> back a node list of the items? Do I have to manual parse the attribute an 
>> dclaa nodeFromID or can I use an xpath expression id(@hrefs)/* (or 
>> something similar)
>
> As you have already seen the DOM in MSXML has nodeFromID to get from an ID 
> value to a node but you are right, if you have an IDREFS attribute which 
> has a space separated list of ID values then you first need to parse/split 
> up that value into ID values to then be able to use nodeFromID on a single 
> ID value.
>
> As for XPath there it is indeed simpler, the id function is smart enough 
> to process such a list to give you a node list (API) or node set (XSLT) 
> back:
>
> Example JScript program testing that feature:
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument.async = false;
> xmlDocument.validateOnParse = true;
> var valid = xmlDocument.load('test2005070401.xml');
> if (valid) {
>   var nodeList = xmlDocument.selectNodes('id(/root/y[1]/@names)');
>   alert(nodeList.length);
> }
>
> when applied to the XML below yields two for the node list length:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE root [
>   <!ELEMENT root (x+, y+)>
>   <!ELEMENT x EMPTY>
>   <!ELEMENT y EMPTY>
>   <!ATTLIST x
>     name ID #REQUIRED>
>   <!ATTLIST y
>     names IDREFS #IMPLIED>
> ]>
> <root>
>   <x name="x1" />
>   <x name="x2" />
>   <y names="x1 x2" />
> </root>
>
>
> Only problem is that an XSLT processor is not required to use an XML 
> parser reading external DTDs so relying on the use of the id function in 
> XPath in XSLT is not portable in general, you need to make sure that the 
> XSLT processor gets the information in the DTD.
>
> -- 
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/ 




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent