Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


How to use XPATH on SVG?

From: "Siegfried Heintze" <siegfried@-------.--->
To: NULL
Date: 11/4/2008 9:28:00 PM
Below is a simplified version of the file from which I am trying to use 
XPATH to extract some values. My code seems to work with no namespaces but 
the SVG namespaces are messing me up (I think).

Here is my XPATH I'm trying to parse with MSXML2. I've tried it with and 
without the "svg:" and it does not work.

Thanks!
Siegfried

_bstr_t bstrQuery(

//L"/html/body/form/table/tbody/tr[2]/td/svg:svg/svg:g/svg:text/[@class=\"tch\"]"

L"/html/svg:svg/svg:g/svg:text/[@class=\"tch\"]"

);

MSXML2::IXMLDOMNodeListPtr pNodeList;

pNodeList = pXMLDoc->selectNodes(bstrQuery);

long lLen = 0;

HRESULT hr = pNodeList->get_length(&lLen);

if ( SUCCEEDED(hr) )

{

for (int i = 0; i < lLen; i++)

{

MSXML2::IXMLDOMNodePtr pXMLNode;

pNodeList->get_item(i,&pXMLNode);

// Get some attribute as an example

_variant_t vNodeValue;

hr = pXMLNode->get_nodeValue(&vNodeValue);

MSXML2::IXMLDOMNodeListPtr pNodeList = pXMLNode->childNodes;

long lLen2 = pNodeList->length;

for(int jj = 0; jj < lLen2; ++jj)

{

MSXML2::IXMLDOMNodePtr pXMLNode;

pNodeList->get_item(jj,&pXMLNode);

_bstr_t text;

text = pXMLNode->text;

TraceW(L" item = %d\n", ((LPCWSTR)text)[0L]);

}

MSXML2::IXMLDOMElement *pNodeElm = NULL;

hr = pXMLNode->QueryInterface(IID_IXMLDOMElement, (void**)&pNodeElm);

if ( SUCCEEDED(hr) )

{

vNodeValue = pNodeElm->getAttribute(L"x");

_bstr_t text = vNodeValue;

TraceW(L"x=%s", (LPCWSTR)text);

pNodeElm->Release();

}

}

}

}



Here is the XML:



<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:svg="http://www.w3.org/2000/svg" 
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
xmlns:xlink="http://www.w3.org/1999/xlink" x="0mm" y="0mm" width="500mm" 
height="390.mm" viewBox="0 0 500 390" enable-background="new 0 0 1390.076 
390.208" xml:space="preserve">


  <g transform="translate( 40.00, 59.55)"><rect id="line 1277 rect" 
title="0002 0001 scan 001 `  ~"    width="12.5"   height="12.5" 
class="keyoutline" />  <text x=" 1"      y=" 5" class="common-up" 
text-anchor="middle">~</text><text x=" 1" y="11" class="common">`</text> 
<text x=" 6" y="11" class="tch">&#24055;</text><text x=" 6" y="11" 
class="ru-up">&#516;</text><text x=" 6" y="11" class="ru-lo">&#517;</text> 
</g>
</svg>
</html>





transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent