Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] How to parse XML document with default namespace with

From: Philippe Poulard <philippe.poulard@------.-----.-->
To: Jack Bush <netbeansfan@-----.---.-->
Date: 11/6/2008 9:12:00 AM
hi,

another piece of code that might be useful:

<xcl:active-sheet
     xmlns:xcl="http://ns.inria.org/active-tags/xcl"
     xmlns:ns="http://www.w3.org/1999/xhtml">
   <xcl:parse-html name="myHtml" source="file:///path/to/file.html"/>
   <xcl:for-each name="myElem" select="{ 
$myHtml/ns:html/ns:body/ns:div[@id='container']/ns:div[@id='content']/ns:table[@class='sresults']/ns:tr/ns:td/ns:a 
}">
     <xcl:echo value="{ string( $myElem ) }"/>
     <xcl:echo value="{ string( $myElem/@href ) }"/>
   </xcl:for-each>
</xcl:active-sheet>

the underlying HTML parser is not tagsoup but nekohtml; if your source 
file is XHTML and not HTML, you can simply use <xcl:parse> (an XML 
parser) instead of <xcl:parse-html> (an HTML parser)

I don't really know what happens for a pure HTML source with the XHTML 
namespace, but you can trace what have been parsed by inserting the 
following operation, for example after the for-each statement:
   <xcl:transform source="{ $myHtml }" output="{ $sys:out }"
     xmlns:sys="http://ns.inria.org/active-tags/sys"/>
for pure HTML sources, nekohtml capitalize the elements to be conform to 
the HTML spec (as stated in the nekohtml parser documentation), and it 
must be the same in the XPath expression

to launch the script, just download reflex 
(http://reflex.gforge.inria.fr/) and type in a console:
java -jar reflex-0.3.2.jar run active-sheet.xcl

-- 
Cordialement,

               ///
              (. .)
  --------ooO--(_)--Ooo--------
|      Philippe Poulard       |
  -----------------------------
  http://reflex.gforge.inria.fr/
        Have the RefleX !

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@l...
subscribe: xml-dev-subscribe@l...
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



transparent
Print
Mail
Like It
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