Tired, Exhausted, searched the web, usenets,forums thorughly but still
clueless. I guess it's time to post on the group :
This is the issue I have been trying to resolve since today morning :
I have an XHTML document in string form which I parse using Xerces
DOMParser (using an InputSource to read it).
Now I am trying to get to a node for which I have the Xpath, using the
XPathAPI.
So something like this :
Document doc = parser.getDocum ent(); // where parser is an instance
of DOMParser
Node onenode =
XPathAPI.select SingleNode(doc, "html/body",doc.getDo cumentElement() );
I am using doc.getDocument Element() as the namespace node because the
namespace is declared there - <html
xmlns="http://ww.w3.org/1999/xhtml">
The problem : selectSingleNod e is always returning NULL.
I have tried almost everything. I saw somewhere on the groups that
somebody had set the Namespaceaware( boolean) to true for DomFactory but
I am not using DOMFactory. I am using DOMParser and I tried
setNamespaces(b oolean) but it cannot find the method (I wonder why -
when it's a derived class from XMLParser).
Anyways, thats the problem I have been dealing with since today morning
(read as 8 hours).
If you have a solution, please help !
Thanks,
Anupam 5 9762 an********@gmai l.com wrote: Document doc = parser.getDocum ent(); // where parser is an instance of DOMParser Node onenode = XPathAPI.select SingleNode(doc, "html/body",doc.getDo cumentElement() );
I am using doc.getDocument Element() as the namespace node because the namespace is declared there - <html xmlns="http://ww.w3.org/1999/xhtml">
The problem : selectSingleNod e is always returning NULL.
If the elements in the XML document are in the default namespace then
your XPath expression needs to a prefix to select/match elements in that
namespace.
See
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>
although that does not show how to do that with the Xerces API. There is
a Java 1.5 example however using the standardized JAXP way to evaluate
XPath expressions.
--
Martin Honnen http://JavaScript.FAQTs.com/
Martin's got the right answer. XPath 1.0 doesn't have the concept of
default namespace; if you want to search for a namespaced node your path
must use prefixes and you need to tell the XPath engine how to resolve
those prefixes.
XPath 2.0 has proposed adding default namespace behavior, I believe.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
I am still clueless about this. Can somebody please help me out?
- Anupam an********@gmai l.com wrote: Tired, Exhausted, searched the web, usenets,forums thorughly but still clueless. I guess it's time to post on the group :
This is the issue I have been trying to resolve since today morning :
I have an XHTML document in string form which I parse using Xerces DOMParser (using an InputSource to read it).
Now I am trying to get to a node for which I have the Xpath, using the XPathAPI.
So something like this :
Document doc = parser.getDocum ent(); // where parser is an instance of DOMParser Node onenode = XPathAPI.select SingleNode(doc, "html/body",doc.getDo cumentElement() );
I am using doc.getDocument Element() as the namespace node because the namespace is declared there - <html xmlns="http://ww.w3.org/1999/xhtml">
The problem : selectSingleNod e is always returning NULL.
I have tried almost everything. I saw somewhere on the groups that somebody had set the Namespaceaware( boolean) to true for DomFactory but I am not using DOMFactory. I am using DOMParser and I tried setNamespaces(b oolean) but it cannot find the method (I wonder why - when it's a derived class from XMLParser).
Anyways, thats the problem I have been dealing with since today morning (read as 8 hours).
If you have a solution, please help !
Thanks, Anupam
Sorry, I was looking at the cached page I guess. Just saw the two
replies.
- Anupam
<an********@gma il.com> wrote: Document doc = parser.getDocum ent(); // where parser is an instance of DOMParser Node onenode = XPathAPI.select SingleNode(doc, "html/body",doc.getDo cumentElement() );
I don't know this XPathAPI class very well. (Are you using Java 1.5?
If so, any reason you're not using XPath from the standard API?)
However, it looks like you're looking for a child of the document
element called "html". Rather, "html" IS the document element. Try
either of the following instead, and see one or both of them work
better.
XPathAPI.select SingleNode(doc, "/html/body",doc.getDo cumentElement() );
XPathAPI.select SingleNode(doc, "html/body",doc);
-- www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dino Morelli |
last post by:
Looking for someone familiar with Xalan-j..
I'm having problems isolating a node in a Document with Xalan-j's
XPathAPI class when that element is in a namespace.
using:
Xalan-j v2.5.1
JDK v1.4.2-b28
Given an XML document that looks like this:
|
by: Scott Simpson |
last post by:
Can you query from a non-root node using XPathAPI's function
selectNodeList(Node contextNode, java.lang.String str)? I'm trying this
using the XPath expression "//*" and I'm getting nothing back. I know the
node I pass to this function has data in it because I'm inspecting it in the
debugger using Eclipse. The Javadoc doesn't say you can't query from a
non-root node. Thanks.
|
by: Kepler |
last post by:
How do you get the height of the client browser in IE? Both
document.body.clientHeight and document.body.offsetHeight return the
height of the document. If the page is long and there's a vertical
scrollbar, you get the height of the entire document, screwing up any
chance of centering a window in the browser using these values.
Is there a way to get the height of the actual browser window and not
the entire page height?
Thanks.
|
by: Edward Yang |
last post by:
My XML document has a default namespace specified by xmlns="some_url". Here
it is:
<?xml version="1.0" encoding="utf-8" ?>
<ssmproject
name="sample" server="sql"
xmlns="mailto:neo_in_matrix@msn.com?subject=ssmprjx"
>
<pr>
|
by: Rune |
last post by:
I have two queries that appear to be exactly the same, but one of them
returns null while the other one returns a valid result!
Can anyone provide an explanation to why this is so? Below is an nunit
test that exposes the problem. I have run the test under both the 1.0
and 1.1 framework with the same result.
public void XPathBooks()
{
XmlDocument smallDoc = new XmlDocument();
| |
by: adam |
last post by:
I tried so many ways to select the node but its not working, please help.
I want to research by the identifier in imsmanifest.xml file, the node could
be item or resource.
XmlDocument doc = new XmlDocument();
try
{
string node = Request.QueryString; //getting nodeid from
query string
doc.Load(Session.ToString()); //load xml file from
|
by: Jesper |
last post by:
Hi,
I've read somewhere that try/catch shoudn't be used as an
alternative to if clauses (maybe it was in C++ regi).
However, when using XmlNode.SelectSingleNode(XPath
expression) to get a node, it throws an exception instead
of returning null if the node doesn't excist. I'm a bit
tentative to use a catch statement to handle this as this
is not in my program considered a severe error. Is my
conception of try/catch in C# wrong in...
|
by: Martin |
last post by:
Hi,
I am using xmldocument.selectsinglenode to query an xml document.
This works perfectly when the document to be queried has no namespace,
however as some as i put a namespace in then null is returned from
selectsinglenode.
I think I am not creating the namespace manager correctly.
I have created a very small sample piece of code (see below) that
|
by: sniper |
last post by:
hi ;
i have this small code that consist in taking the name of the user and
writing it in the same form as an output.the name is relative to
/data/valid/string1
In my Js code i want to access the value of /data/valid/string1 (The
name seised by the user)
and alert the name as result
Can you help me to achieve this?
<?xml version="1.0" encoding="UTF-8"?>
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |