You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Rackl, Robert G" <ro...@boeing.com> on 2009/07/27 18:23:35 UTC

Using Schema in DOMCount

After having used xml on Windows, I am now trying to use xml in Linux
using xerces. I am new to xerces and fairly new to C++. Successfully
compiled the DOMCount sample program. But I am unsuccessful in trying to
have DOMCount validate the input xml file using the command

./DOMCount -v=always -s -f ~/practice/SamplePanelDat.xml

(tried various combinations of -n, -s, -f options - to no avail)

Many errors are reported as if the schema file did not exist (but it
does). The first few lines of the input file are thus:

<?xml version="1.0" encoding="UTF-8"?>
<PanelData xmlns="http://www.w3schools.com"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="~/practice/ADINB_PanelData.xsd">
	<Identification ID="12345" Case="Sample for demonstrating XML
format, successful aero data extraction, fictitious data"/>

The first few lines of the schema file ADINB_PanelData.xsd are thus:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 rel. 2 sp1 (http://www.altova.com) by
WILLIAM ANDERSON (BOEING SHARED SERVICES GROUP) -->
<xs:schema xmlns="http://www.w3schools.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="PanelData">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="Identification"/>

What's wrong, please?

  -_r4_\.
___`o-#^o`__

Re: XMLString Class and ordinary C-strings

Posted by David Bertoni <db...@apache.org>.
Rackl, Robert G wrote:
> Using the DOMCount sample as a guide, I am developing a module with a
> bunch of subroutines to parse and validate an XML file, and then to
> extract data from it. The subroutines are to be called from Fortran, and
> all output to cerr is to be converted to go to status strings in the
> calls from Fortran. I can parse/validate the document by a call from
> Fortran. I am stuck at converting ordinary plain ASCII null-terminated
> C-strings to XMLStrings and vice versa. How is that done, please?
You generally shouldn't convert the XML document data to UTF-16. 
Instead, let the parser determine the encoding from the data itself.

For output, you should probably convert all UTF-16 strings to UTF-8, to 
preserve data fidelity.  This is usually not a problem, because UTF-8 is 
compatible with US-ASCII.

You might have some issues displaying some strings to the console if 
those strings have characters that aren't supported by the current code 
page, but it's the best compromise to maintain data fidelity.

To transcode from UTF-16 to and from UTF-8, you need a UTF-8 transcoder. 
You should search the archives of the user and developer list, as you 
will find other emails that discuss this topic, along with code snippets.

Dave

RE: XMLString Class and ordinary C-strings

Posted by John Lilley <jl...@datalever.com>.
If they are really ASCII, you can just convert each character to n XMLCh and append them to the string one at the time.

You can also use Xerces' transcoder to transcode from the native locale's 8-bit code page, which unless it is something like EBCDIC will have ASCII as its lower 127 characters.

john

________________________________________
From: Rackl, Robert G [robert.g.rackl@boeing.com]
Sent: Wednesday, July 29, 2009 4:41 PM
To: c-users@xerces.apache.org
Subject: XMLString Class and ordinary C-strings

Using the DOMCount sample as a guide, I am developing a module with a
bunch of subroutines to parse and validate an XML file, and then to
extract data from it. The subroutines are to be called from Fortran, and
all output to cerr is to be converted to go to status strings in the
calls from Fortran. I can parse/validate the document by a call from
Fortran. I am stuck at converting ordinary plain ASCII null-terminated
C-strings to XMLStrings and vice versa. How is that done, please?

  -_r4_\.
___`o-#^o`__

Re: Extracting data from nodes deep down in the hierarchy

Posted by Brian and Victoria <bn...@nc.rr.com>.
You could walk the document nodes using a xerces::DOMTreeWalker and its 
functions...

::nextSibling()
::firstChild()
::nextChild()
::parentNode()

Each of these returns a xerces::DOMNode pointer and you can use its 
functions (e.g., ::getNodeValue()) to extract the node data.

Since your document conforms to a schema, you know how the nodes are 
ordered and nested.


Rackl, Robert G wrote:
> Attached is a sample XML file from which I need to extract data. I am
> using the DOM document approach, learning from the DOMCount sample code.
> I am able to extract the data from the "Identification", "Grid",
> "Solution", and "Results" nodes. I am also able to list the Names of the
> three nodes called "Panel" using the getElementsByTagName method from
> the document root. Where I am running into trouble is extracting the
> attribute data for each element called "Node" [sorry about the use of
> "Node" here for the corners of an aircraft fuselage panel] for a
> particular Panel. What should be the approach here, please? (I tried
> using getElementsByTagName from a "Panel" node - did not work; I tried
> descending down the subtree using child nodes - could not make it work;
> I thought about using filters - did not know where/how to start). Can
> you point me to sample code for the approach you would recommend,
> please?
>
>   -_r4_\.
> ___`o-#^o`__
>   


Extracting data from nodes deep down in the hierarchy

Posted by "Rackl, Robert G" <ro...@boeing.com>.
Attached is a sample XML file from which I need to extract data. I am
using the DOM document approach, learning from the DOMCount sample code.
I am able to extract the data from the "Identification", "Grid",
"Solution", and "Results" nodes. I am also able to list the Names of the
three nodes called "Panel" using the getElementsByTagName method from
the document root. Where I am running into trouble is extracting the
attribute data for each element called "Node" [sorry about the use of
"Node" here for the corners of an aircraft fuselage panel] for a
particular Panel. What should be the approach here, please? (I tried
using getElementsByTagName from a "Panel" node - did not work; I tried
descending down the subtree using child nodes - could not make it work;
I thought about using filters - did not know where/how to start). Can
you point me to sample code for the approach you would recommend,
please?

  -_r4_\.
___`o-#^o`__

Re: XMLString Class and ordinary C-strings

Posted by David Bertoni <db...@apache.org>.
BRM wrote:
> See XMLString::transcode(). Works boths ways. Just remember to use XMLString::release() as well.
> 
> char* myCString = "some string";
> XMLCh* myXMLString = XMLString::transcode(myCString);
> // use it
> ...
> if (myXMLString != NULL) XMLString::release(&myXMLString);
> 
> or
> 
> ...
> const XMLCh* myXMLString = someNode->getTagName();
> char* myCString = XMLString::transcode(myXMLString);
> 
> // use it
> ...
> if (myCString != NULL) XMLString::release(&myCString);
Using XMLString::transcode() is dangerous when you don't know if the 
strings you're transcoding are compatible with the local code page. The 
safest approach is to use UTF-8, since it can represent all Unicode 
characters.

Dave

Re: XMLString Class and ordinary C-strings

Posted by BRM <bm...@yahoo.com>.
See XMLString::transcode(). Works boths ways. Just remember to use XMLString::release() as well.

char* myCString = "some string";
XMLCh* myXMLString = XMLString::transcode(myCString);
// use it
...
if (myXMLString != NULL) XMLString::release(&myXMLString);

or

...
const XMLCh* myXMLString = someNode->getTagName();
char* myCString = XMLString::transcode(myXMLString);

// use it
...
if (myCString != NULL) XMLString::release(&myCString);

Ben


----- Original Message ----
From: "Rackl, Robert G" <ro...@boeing.com>
To: c-users@xerces.apache.org
Sent: Wednesday, July 29, 2009 6:41:26 PM
Subject: XMLString Class and ordinary C-strings

Using the DOMCount sample as a guide, I am developing a module with a
bunch of subroutines to parse and validate an XML file, and then to
extract data from it. The subroutines are to be called from Fortran, and
all output to cerr is to be converted to go to status strings in the
calls from Fortran. I can parse/validate the document by a call from
Fortran. I am stuck at converting ordinary plain ASCII null-terminated
C-strings to XMLStrings and vice versa. How is that done, please?

  -_r4_\.
___`o-#^o`__


XMLString Class and ordinary C-strings

Posted by "Rackl, Robert G" <ro...@boeing.com>.
Using the DOMCount sample as a guide, I am developing a module with a
bunch of subroutines to parse and validate an XML file, and then to
extract data from it. The subroutines are to be called from Fortran, and
all output to cerr is to be converted to go to status strings in the
calls from Fortran. I can parse/validate the document by a call from
Fortran. I am stuck at converting ordinary plain ASCII null-terminated
C-strings to XMLStrings and vice versa. How is that done, please?

  -_r4_\.
___`o-#^o`__

RE: Using Schema in DOMCount

Posted by "Rackl, Robert G" <ro...@boeing.com>.
Thank you, got it to work. ~ shortcut does indeed not work, must use
absolute path. 

  -_r4_\.
___`o-#^o`__

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Monday, July 27, 2009 11:05
To: c-users@xerces.apache.org
Subject: Re: Using Schema in DOMCount

Sorry, my mistake: the correct attribute name is just
xsi:schemaLocation.
If you still get errors, try using an absoluta path, without using the ~
shortcut

Alberto

Rackl, Robert G wrote:
> Thank you, Alberto.
> Modified the command like so:
>
> ./DOMCount.g++ -v=always -n -s -f ~/practice/SamplePanelDat.xml
>
> Modified the first few lines of the input file as follows:
>
> <?xml version="1.0" encoding="UTF-8"?> <PanelData 
> xmlns="http://www.w3schools.com"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:namespaceSchemaLocation="http://www.w3schools.com
> ~/practice/ADINB_PanelData.xsd">
> 	<Identification ID="12345" Case="Sample for demonstrating XML
format, 
> successful aero data extraction, fictitious data"/>
>  
> Schema file not changed.
>
> I am still getting the same errors. Do you see anything else wrong?
>
>   -_r4_\.
> ___`o-#^o`__
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Monday, July 27, 2009 09:56
> To: c-users@xerces.apache.org
> Subject: Re: Using Schema in DOMCount
>
> Two things are wrong here:
> 1) you need the -n option to enable namespaces
> 2) the schema is for the namespace http://www.w3schools.com, the XML 
> document uses that namespace, but you bind them by using the 
> xsi:noNamespaceSchemaLocation (that should be used for documents that 
> don't use namespaces). You should use an attribute 
> xsi:namespaceSchemaLocation="http://www.w3schools.com
> ~/practice/ADINB_PanelData.xsd"
>
> Alberto
>
> Rackl, Robert G wrote:
>   
>> After having used xml on Windows, I am now trying to use xml in Linux

>> using xerces. I am new to xerces and fairly new to C++. Successfully 
>> compiled the DOMCount sample program. But I am unsuccessful in trying

>> to have DOMCount validate the input xml file using the command
>>
>> ./DOMCount -v=always -s -f ~/practice/SamplePanelDat.xml
>>
>> (tried various combinations of -n, -s, -f options - to no avail)
>>
>> Many errors are reported as if the schema file did not exist (but it 
>> does). The first few lines of the input file are thus:
>>
>> <?xml version="1.0" encoding="UTF-8"?> <PanelData 
>> xmlns="http://www.w3schools.com"
>> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> 	xsi:noNamespaceSchemaLocation="~/practice/ADINB_PanelData.xsd">
>> 	<Identification ID="12345" Case="Sample for demonstrating XML
>>     
> format,
>   
>> successful aero data extraction, fictitious data"/>
>>
>> The first few lines of the schema file ADINB_PanelData.xsd are thus:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!-- edited with XMLSpy v2008 rel. 2 sp1 (http://www.altova.com) by 
>> WILLIAM ANDERSON (BOEING SHARED SERVICES GROUP) --> <xs:schema 
>> xmlns="http://www.w3schools.com"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> targetNamespace="http://www.w3schools.com"
>> elementFormDefault="qualified" attributeFormDefault="unqualified">
>> 	<xs:element name="PanelData">
>> 		<xs:complexType>
>> 			<xs:sequence>
>> 				<xs:element ref="Identification"/>
>>
>> What's wrong, please?
>>
>>   -_r4_\.
>> ___`o-#^o`__
>>
>>   
>>     
>
>
>   


Re: Using Schema in DOMCount

Posted by Alberto Massari <am...@datadirect.com>.
Sorry, my mistake: the correct attribute name is just xsi:schemaLocation.
If you still get errors, try using an absoluta path, without using the ~ 
shortcut

Alberto

Rackl, Robert G wrote:
> Thank you, Alberto.
> Modified the command like so:
>
> ./DOMCount.g++ -v=always -n -s -f ~/practice/SamplePanelDat.xml
>
> Modified the first few lines of the input file as follows:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <PanelData xmlns="http://www.w3schools.com"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:namespaceSchemaLocation="http://www.w3schools.com
> ~/practice/ADINB_PanelData.xsd">
> 	<Identification ID="12345" Case="Sample for demonstrating XML
> format, successful aero data extraction, fictitious data"/>
>  
> Schema file not changed.
>
> I am still getting the same errors. Do you see anything else wrong?
>
>   -_r4_\.
> ___`o-#^o`__
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com] 
> Sent: Monday, July 27, 2009 09:56
> To: c-users@xerces.apache.org
> Subject: Re: Using Schema in DOMCount
>
> Two things are wrong here:
> 1) you need the -n option to enable namespaces
> 2) the schema is for the namespace http://www.w3schools.com, the XML
> document uses that namespace, but you bind them by using the
> xsi:noNamespaceSchemaLocation (that should be used for documents that
> don't use namespaces). You should use an attribute
> xsi:namespaceSchemaLocation="http://www.w3schools.com
> ~/practice/ADINB_PanelData.xsd"
>
> Alberto
>
> Rackl, Robert G wrote:
>   
>> After having used xml on Windows, I am now trying to use xml in Linux 
>> using xerces. I am new to xerces and fairly new to C++. Successfully 
>> compiled the DOMCount sample program. But I am unsuccessful in trying 
>> to have DOMCount validate the input xml file using the command
>>
>> ./DOMCount -v=always -s -f ~/practice/SamplePanelDat.xml
>>
>> (tried various combinations of -n, -s, -f options - to no avail)
>>
>> Many errors are reported as if the schema file did not exist (but it 
>> does). The first few lines of the input file are thus:
>>
>> <?xml version="1.0" encoding="UTF-8"?> <PanelData 
>> xmlns="http://www.w3schools.com"
>> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> 	xsi:noNamespaceSchemaLocation="~/practice/ADINB_PanelData.xsd">
>> 	<Identification ID="12345" Case="Sample for demonstrating XML
>>     
> format, 
>   
>> successful aero data extraction, fictitious data"/>
>>
>> The first few lines of the schema file ADINB_PanelData.xsd are thus:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!-- edited with XMLSpy v2008 rel. 2 sp1 (http://www.altova.com) by 
>> WILLIAM ANDERSON (BOEING SHARED SERVICES GROUP) --> <xs:schema 
>> xmlns="http://www.w3schools.com"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> targetNamespace="http://www.w3schools.com"
>> elementFormDefault="qualified" attributeFormDefault="unqualified">
>> 	<xs:element name="PanelData">
>> 		<xs:complexType>
>> 			<xs:sequence>
>> 				<xs:element ref="Identification"/>
>>
>> What's wrong, please?
>>
>>   -_r4_\.
>> ___`o-#^o`__
>>
>>   
>>     
>
>
>   


RE: Using Schema in DOMCount

Posted by "Rackl, Robert G" <ro...@boeing.com>.
Thank you, Alberto.
Modified the command like so:

./DOMCount.g++ -v=always -n -s -f ~/practice/SamplePanelDat.xml

Modified the first few lines of the input file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<PanelData xmlns="http://www.w3schools.com"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:namespaceSchemaLocation="http://www.w3schools.com
~/practice/ADINB_PanelData.xsd">
	<Identification ID="12345" Case="Sample for demonstrating XML
format, successful aero data extraction, fictitious data"/>
 
Schema file not changed.

I am still getting the same errors. Do you see anything else wrong?

  -_r4_\.
___`o-#^o`__

-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Monday, July 27, 2009 09:56
To: c-users@xerces.apache.org
Subject: Re: Using Schema in DOMCount

Two things are wrong here:
1) you need the -n option to enable namespaces
2) the schema is for the namespace http://www.w3schools.com, the XML
document uses that namespace, but you bind them by using the
xsi:noNamespaceSchemaLocation (that should be used for documents that
don't use namespaces). You should use an attribute
xsi:namespaceSchemaLocation="http://www.w3schools.com
~/practice/ADINB_PanelData.xsd"

Alberto

Rackl, Robert G wrote:
> After having used xml on Windows, I am now trying to use xml in Linux 
> using xerces. I am new to xerces and fairly new to C++. Successfully 
> compiled the DOMCount sample program. But I am unsuccessful in trying 
> to have DOMCount validate the input xml file using the command
>
> ./DOMCount -v=always -s -f ~/practice/SamplePanelDat.xml
>
> (tried various combinations of -n, -s, -f options - to no avail)
>
> Many errors are reported as if the schema file did not exist (but it 
> does). The first few lines of the input file are thus:
>
> <?xml version="1.0" encoding="UTF-8"?> <PanelData 
> xmlns="http://www.w3schools.com"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:noNamespaceSchemaLocation="~/practice/ADINB_PanelData.xsd">
> 	<Identification ID="12345" Case="Sample for demonstrating XML
format, 
> successful aero data extraction, fictitious data"/>
>
> The first few lines of the schema file ADINB_PanelData.xsd are thus:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XMLSpy v2008 rel. 2 sp1 (http://www.altova.com) by 
> WILLIAM ANDERSON (BOEING SHARED SERVICES GROUP) --> <xs:schema 
> xmlns="http://www.w3schools.com"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.w3schools.com"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> 	<xs:element name="PanelData">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element ref="Identification"/>
>
> What's wrong, please?
>
>   -_r4_\.
> ___`o-#^o`__
>
>   


Re: Using Schema in DOMCount

Posted by Alberto Massari <am...@datadirect.com>.
Two things are wrong here:
1) you need the -n option to enable namespaces
2) the schema is for the namespace http://www.w3schools.com, the XML 
document uses that namespace, but you bind them by using the 
xsi:noNamespaceSchemaLocation (that should be used for documents that 
don't use namespaces). You should use an attribute 
xsi:namespaceSchemaLocation="http://www.w3schools.com 
~/practice/ADINB_PanelData.xsd"

Alberto

Rackl, Robert G wrote:
> After having used xml on Windows, I am now trying to use xml in Linux
> using xerces. I am new to xerces and fairly new to C++. Successfully
> compiled the DOMCount sample program. But I am unsuccessful in trying to
> have DOMCount validate the input xml file using the command
>
> ./DOMCount -v=always -s -f ~/practice/SamplePanelDat.xml
>
> (tried various combinations of -n, -s, -f options - to no avail)
>
> Many errors are reported as if the schema file did not exist (but it
> does). The first few lines of the input file are thus:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <PanelData xmlns="http://www.w3schools.com"
> 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	xsi:noNamespaceSchemaLocation="~/practice/ADINB_PanelData.xsd">
> 	<Identification ID="12345" Case="Sample for demonstrating XML
> format, successful aero data extraction, fictitious data"/>
>
> The first few lines of the schema file ADINB_PanelData.xsd are thus:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- edited with XMLSpy v2008 rel. 2 sp1 (http://www.altova.com) by
> WILLIAM ANDERSON (BOEING SHARED SERVICES GROUP) -->
> <xs:schema xmlns="http://www.w3schools.com"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.w3schools.com"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> 	<xs:element name="PanelData">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element ref="Identification"/>
>
> What's wrong, please?
>
>   -_r4_\.
> ___`o-#^o`__
>
>