 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Rob Cooke Guest
|
Posted: Sat May 05, 2007 7:25 pm Post subject: ` |
|
|
Running Delphi 2007 for Win32
I just discovered the IDOMNodeSelect interface in the xmldom unit. I've been wanting forever to use XPath queries
against IXMLDocument objects without using MSXML directly, and now it looks like I can. I'm having trouble getting it
to work when the xml document contains namespaces. A fragment of my doc:
<?xml version="1.0"?>
<bml:BatchInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bml="http://www.wbf.org/xml/BatchML-V02" xsi:schemaLocation="http://www.wbf.org/xml/BatchML-V02
file:///c:/Projects/BatchML/BatchML-V02.xsd">
<bml:RecipeBuildingBlock>
<bml:Description>Inline Dilution</bml:Description>
<bml:RecipeElement>
<bml:ID>5002</bml:ID>
<bml:RecipeElementType>Phase</bml:RecipeElementType>
</bml:RecipeElement>
</bml:RecipeBuildingBlock>
</bml:BatchInformation)
When I tried the following function:
procedure TForm1.GetPhases;
var
doc: IXmlDocument;
sel: IDOMNodeSelect;
nl: IDOMNodeList;
begin
doc := LoadXmlDocument(ExtractFilePath(Application.ExeName) + 'RecipeBuildingBlocks.xml');
doc.DocumentElement.DeclareNamespace('bml', 'http://www.wbf.org/xml/BatchML-V02');
sel := doc.DOMDocument as IDOMNodeSelect;
nl := sel.selectNodes('//bml:RecipeBuildingBlock');
ShowMessage(IntToStr(nl.length));
end;
I get the runtime error message "Reference to undeclared namespace prefix: 'bml'"
It seems that dom.DocumentElement is not the place to declare the namespace prefix, but I can't find anywhere else to do
it.
This code works fine for documents in which namespaces are not used. Any suggestions, please?
Thanks, Rob Cooke |
|
| Back to top |
|
 |
Rob Cooke Guest
|
Posted: Sat May 05, 2007 7:31 pm Post subject: Subject should be: IDOMNodeSelect and namespace declarations |
|
|
On Sat, 05 May 2007 10:25:10 -0400, Rob Cooke <rob (AT) rjcooke (DOT) com> wrote:
| Quote: | Running Delphi 2007 for Win32
I just discovered the IDOMNodeSelect interface in the xmldom unit. I've been wanting forever to use XPath queries
against IXMLDocument objects without using MSXML directly, and now it looks like I can. I'm having trouble getting it
to work when the xml document contains namespaces. A fragment of my doc:
?xml version="1.0"?
bml:BatchInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bml="http://www.wbf.org/xml/BatchML-V02" xsi:schemaLocation="http://www.wbf.org/xml/BatchML-V02
file:///c:/Projects/BatchML/BatchML-V02.xsd"
<bml:RecipeBuildingBlock
<bml:Description>Inline Dilution</bml:Description
<bml:RecipeElement
<bml:ID>5002</bml:ID
<bml:RecipeElementType>Phase</bml:RecipeElementType>
</bml:RecipeElement
</bml:RecipeBuildingBlock
/bml:BatchInformation)
When I tried the following function:
procedure TForm1.GetPhases;
var
doc: IXmlDocument;
sel: IDOMNodeSelect;
nl: IDOMNodeList;
begin
doc := LoadXmlDocument(ExtractFilePath(Application.ExeName) + 'RecipeBuildingBlocks.xml');
doc.DocumentElement.DeclareNamespace('bml', 'http://www.wbf.org/xml/BatchML-V02');
sel := doc.DOMDocument as IDOMNodeSelect;
nl := sel.selectNodes('//bml:RecipeBuildingBlock');
ShowMessage(IntToStr(nl.length));
end;
I get the runtime error message "Reference to undeclared namespace prefix: 'bml'"
It seems that dom.DocumentElement is not the place to declare the namespace prefix, but I can't find anywhere else to do
it.
This code works fine for documents in which namespaces are not used. Any suggestions, please?
Thanks, Rob Cooke |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|