Thanks,
This is my revised code..
here I am setting the Location provider before building the tree..
TinyBuilder docBuilder = new TinyBuilder();
docBuilder.setLineNumbering(true);
LocationMap p = new LocationMap();
int locId = p.allocateLocationId("InValid.xml", 55);
System.out.println("Loc Id: " + locId);
Configuration c = tfactory.getConfiguration();
PipelineConfiguration pipe = c.makePipelineConfiguration();
pipe.setLocationProvider(p);
docBuilder.setPipelineConfiguration(pipe);
try {
Transformer trans = tfactory.newTransformer();
trans.transform(xmlNodeInfo, docBuilder);
} catch (TransformerException e) {
}
if (docBuilder == null)
return null;
try {
docBuilder.startDocument(0);
docBuilder.startElement(xmlNodeInfo.getNameCode(), -1,
locId, 0);
} catch (XPathException e) {
e.printStackTrace();
}
NodeInfo rootNode = docBuilder.getCurrentRoot();
rootNode = (NodeInfo) (rootNode.iterateAxis(Axis.CHILD,
NodeKindTest.ELEMENT).next());
System.out.println("Line no: " + rootNode.getLineNumber() );
But still I am getting the line number 0 only..
what is wrong in the above code..?
Thanks
Selvam
selvam wrote:
>
> Thanks,
>
> I just added the following line before calling startElement,
>
> docBuilder.startDocument(0);
> docBuilder.startElement(xmlNodeInfo.getNameCode(), -1, locId, 0);
>
> Now I am getting the rootNode correctly..
> But still I am not getting the line number..
>
> I am calling rootNode.getLineNumber() to get the line number..
>
> Still am I missing anything..?
>
> any help would be more thankful..
>
> Thanks
> Selvam
>
>
>
> selvam wrote:
>>
>> Thanks.. I am working on this..I need some help wheter I am doing it in
>> correct way or not..
>>
>> I am creating an object of LocationMap class and called
>> allocateLocationId method by passing document name and the line number of
>> the node..
>>
>> TinyBuilder docBuilder = new TinyBuilder();
>> docBuilder.setLineNumbering(true);
>> try {
>> Transformer trans = tfactory.newTransformer();
>> trans.transform(xmlNodeInfo, docBuilder);
>> } catch (TransformerException e) {
>> }
>>
>> if (docBuilder == null)
>> return null;
>> TinyTree tree = docBuilder.getTree();
>> LocationMap p = new LocationMap();
>>
>> int locId = p.allocateLocationId("InValid.xml", 55); // Here 55
>> is line number..
>>
>> System.out.println("Loc Id: " + locId);
>>
>> docBuilder.getPipelineConfiguration().setLocationProvider(p); //
>> Set the location provider..
>> try {
>> docBuilder.startElement(xmlNodeInfo.getNameCode(), -1, locId,
>> 0); // I am not sure this is correct or not
>> } catch (XPathException e) {
>> e.printStackTrace();
>> }
>> NodeInfo rootNode = docBuilder.getCurrentRoot();
>>
>> rootNode = (NodeInfo) (rootNode.iterateAxis(Axis.CHILD,
>> NodeKindTest.ELEMENT).next());
>> System.out.println("Line no: " + rootNode.getLineNumber() );
>>
>> But the result root node is null.. I dont know why..? am I missing
>> something..
>>
>> Some hint would be greater helpful...
>>
>> Thanks
>> Selvam
>>
>>
>> Michael Kay wrote:
>>>
>>>> Now I am doing this validation using Transformer class in the
>>>> following way,
>>>>
>>> ...
>>>>
>>>> - any example how can I use the ReceivingContentHandler in my
>>>> above example..
>>>
>>> No, I'm sorry, I will have to leave you to work this out for yourself.
>>> That's because the only way I can find an approach that works is to
>>> write
>>> and test the code myself, and I'm not prepared to do that.
>>>
>>> Michael Kay
>>> http://www.saxonica.com/
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Take Surveys. Earn Cash. Influence the Future of IT
>>> Join SourceForge.net's Techsay panel and you'll get the chance to share
>>> your
>>> opinions on IT & business topics through brief surveys-and earn cash
>>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>>> _______________________________________________
>>> saxon-help mailing list
>>> saxon-help@...
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/getLineNumber%28%29-tf3434070.html#a9611851
Sent from the saxon-help mailing list archive at Nabble.com.
|