|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Fwd: xmlns ignoreMichael Kay mike at saxonica.comTue Sep 15 15:35:25 PDT 2009
You clearly didn't understand David's answer.
You can no more "ignore" a namespace declaration in your source document
than you can ignore the first character of each element name. The namespace
is an intrinsic part of the names of your elements, and when selecting
elements by name, you need to be aware of it.
If you want to use unqualified names in your XQuery expression to refer to
names in a namespace, you can do this by means of a default namespace
declaration in the XQuery prolog:
declare default element namespace " <http://www.portalfiscal.inf.br/nfe>
http://www.portalfiscal.inf.br/nfe"
However, you need to be aware that this affects the interpretation of all
unprefixed names in your query, not only those in a path expression.
If you don't want to change the source of the query, you can achieve the
same effect using the Saxon API:
comp.declareNamespace("", " <http://www.portalfiscal.inf.br/nfe>
http://www.portalfiscal.inf.br/nfe");
Your example query will then work as written. Note, however, that this is a
very different thing from "ignoring" the namespace.
Regards,
Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay
_____
From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf
Of Sérgio Mariano Dias
Sent: 15 September 2009 14:07
To: http://x-query.com/mailman/listinfo/talk
Subject: Fwd: xmlns ignore
Hi,
This is a complete code test:
//--------------------------------------------------------------------------
-------------------------------------------------------
Processor proc = new Processor(false);
XQueryCompiler comp = proc.newXQueryCompiler();
XdmNode source = proc.newDocumentBuilder().build(new
StreamSource(inputFile));
XQueryExecutable exp = comp.compile("/NFe/infNFe/ide/natOp");
XQueryEvaluator eval = exp.load();
eval.setContextItem(source);
XdmItem i =eval.evaluateSingle();
System.out.println(i.getStringValue());
XdmValue v = eval.evaluate();
System.out.println(v.size());
//--------------------------------------------------------------------------
-------------------------------------------------------
that is the xml file:
//--------------------------------------------------------------------------
-------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe Id="NFe2907" versao="1.10">
<ide>
<cUF>29</cUF>
<cNF>123658</cNF>
<natOp>Venda - direta</natOp>
....
//--------------------------------------------------------------------------
-------------------------------------------------------
The ""http://www.portalfiscal.inf.br/nfe"" return page not found. If I
remove the addres, the program return the correct value. That is way a fink
to ignore the addres. Is that possible?
Regards,
2009/9/11 David Carlisle <http://x-query.com/mailman/listinfo/talk>
> I have a problem to ignore a xmls attribute in a tag and did not found
> information how to ignore this attribute. Somebody can help me.
A namespace declaration is not an attribute in the XDM model used by
XPath and Xquery. The name of an element includes the namespace.
Most likely the part of teh code that you don't show
= comp.compile("/.../... ...");
is selecting elements in no-namespace, and you should change it to
select elements in the namespace used in your xml source.
either by using a prefix
/p:aa/p:bb
and binding p to the namespace used in the source, or by setting the
default namespace in the xquery to that used in the source.
David
________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________
--
Sérgio Mariano
--
Sérgio Mariano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20090915/73c0cba1/attachment.htm
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






