![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Processing IDRefs DOMDocument >Thread Next - Re: Processing IDRefs DOMDocument Re: Processing IDRefs DOMDocumentTo: 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/ | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
