如何在Xalan程序中从XML获取处理指令?

时间:2012-02-27 05:32:51

标签: xalan

我正在使用Xalan并想知道如何获得处理指令。 我想获得样式表处理指令。

日Thnx

1 个答案:

答案 0 :(得分:0)

        XMLPlatformUtils::Initialize();
        XPathEvaluator::initialize();
        {
        const XalanDOMString            theFileName(fileName);
        const LocalFileInputSource      theInputSource(theFileName.c_str());


        XalanSourceTreeInit             theSourceTreeInit;
        XalanSourceTreeDOMSupport       theDOMSupport;
        XalanSourceTreeParserLiaison    theLiaison(theDOMSupport);
        theDOMSupport.setParserLiaison(&theLiaison);

        XalanDocument* const            theDocument =
                                          theLiaison.parseXMLStream(theInputSource);

       if(!theDocument) {
           std::cerr << "Failed to create XalanDocument" << std::endl;
           retValue = -1;
       }

       XalanDocumentPrefixResolver     thePrefixResolver(theDocument);
       XPathEvaluator                  theEvaluator;

       XalanNode* const rootContextNode = theEvaluator.selectSingleNode(
                                                theDOMSupport, theDocument,
                             XalanDOMString("/processing-instruction('xml-stylesheet')").c_str(),
                                                thePrefixResolver);

       if(rootContextNode) {
//<Now do whatever u want :)>
       }