[xsd-users] Re: Loading URLs

Patrick Shinpaugh shpatric at vt.edu
Thu Nov 2 09:51:24 EST 2006


Hi Boris,
Thanks for the heads up about lack of https support - I guess I assumed
Xerces would support it being an Apache project. The libcurl solution
should be good and easy to implement.

Unfortunately I have run into another problem which I cannot be sure is
XSD specific. Basically I am traversing the DOMNodes using a recursive
function and as a test if the node is a x3d::Transform then grab it and
print out the info accessed directly from the Transform xsd-generated
class and compare it to the data printed directly from the DOMNodes. So
as I traverse the nodes, everything works great - I am able to grab the
data from the first Transform - until I reach the second Transform and
attempt to print its info. The data output is indented for the DOMNode
output and not indented for the Transform direct access.

...
...
  Transform
    bboxCenter 0 0 0
    bboxSize -1 -1 -1
    center 0 0 0
    containerField children
    rotation 0 0 1 0
    scale 0.875 0.875 0.875
    scaleOrientation 0 0 1 0
    translation 0 3 0
Transform
containerField: children
bboxCenter: 0 0 0
bboxSize: -1 -1 -1
center: 0 0 0
rotation: 0 0 1 0
scale: 0.875 0.875 0.875
scaleOrientation: 0 0 1 0
translation: 0 3 0

    LOD
      bboxCenter 0 0 0
      bboxSize -1 -1 -1
      center 0 0 0
      containerField children
      range 200 2000 20000

      Transform
        bboxCenter 0 0 0
        bboxSize -1 -1 -1
        center 0 0 0
        containerField children
        rotation 0 1 0 1.57
        scale 0.45 0.45 0.45
        scaleOrientation 0 0 1 0
        translation 0 0 0
Segmentation fault (core dumped)

Unfortunately, it segfaults with gdb backtrace:

(gdb) bt
#0  0x054fdc70 in __dynamic_cast ()
at /usr/local/xsd/libxsd/xsd/cxx/tree/types.hxx:1214
#1  0x0804b4eb in printX3DNodeData (current=0x9c62058) at driver.cxx:28
#2  0x0804b8fa in getChildren (current=0x9c61820, indent=6) at
driver.cxx:76
#3  0x0804b780 in getChildren (current=0x9c609c8, indent=4) at
driver.cxx:97
#4  0x0804b780 in getChildren (current=0x9c99ea8, indent=2) at
driver.cxx:97
#5  0x0804b780 in getChildren (current=0x9c98200, indent=0) at
driver.cxx:97
#6  0x0804bbb7 in main (argc=0, argv=0x0) at driver.cxx:148

The code in question looks like this:

int printX3DNodeData( DOMNode* current )
{
        xml_schema::type& t ( *reinterpret_cast<xml_schema::type*>
( current->getUserData (xml_
schema::tree_node_key)));
        x3d::Transform& current_transform (dynamic_cast<x3d::Transform&>
(t));
        cout << "Transform" << endl;
        cout << "containerField: " << current_transform.containerField()
<< endl;
        cout << "bboxCenter: " << current_transform.bboxCenter() <<
endl;
        cout << "bboxSize: " << current_transform.bboxSize() << endl;
        cout << "center: " << current_transform.center() << endl;
        cout << "rotation: " << current_transform.rotation() << endl;
        cout << "scale: " << current_transform.scale() << endl;
        cout << "scaleOrientation: " <<
current_transform.scaleOrientation() << endl;
        cout << "translation: " << current_transform.translation() <<
endl;
}

int getChildren( DOMNode* current, int indent = 0 )
{
  try
  {
        for( DOMNode* cur = current->getFirstChild();
                cur != 0; cur = cur->getNextSibling() )
        {
                for( int i=0;i<indent;i++ )
                        cout << " ";
                cout << XMLString::transcode( cur->getNodeName() ) <<
endl;
                switch( cur->getNodeType() )
                {
                        case DOMNode::ELEMENT_NODE:
                        {
                                if( cur->hasAttributes() )
                                {
                                        DOMNamedNodeMap* attributes =
cur->getAttributes();
                                        if( attributes )
                                        {
                                                for( int
i=0;i<attributes->getLength();i++ )
                                                {
                                                        for( int
j=0;j<indent+2;j++ )
                                                                cout <<
" ";
                                                        DOMNode* attr =
attributes->item(i);
                                                        cout <<
XMLString::transcode( attr->getNodeName() );

if( attr->getNodeValue() )
                                                        {
                                                                cout <<
" " << XMLString::transcode( attr->getNodeValue() ) << endl;
                                                        }
                                                }
                                        }
                                }

if( XMLString::transcode( cur->getNodeName() ) ==
std::string( "Transform" ) )
                                {
                                        if( cur->hasAttributes() )
                                        {
                                                printX3DNodeData( cur );
                                        }
                                }
                                break;
                        }
                case DOMNode::ATTRIBUTE_NODE:
                case DOMNode::TEXT_NODE:
                case DOMNode::CDATA_SECTION_NODE:
                case DOMNode::ENTITY_REFERENCE_NODE:
                case DOMNode::ENTITY_NODE:
                case DOMNode::PROCESSING_INSTRUCTION_NODE:
                case DOMNode::COMMENT_NODE:
                case DOMNode::DOCUMENT_NODE:
                case DOMNode::DOCUMENT_TYPE_NODE:
                case DOMNode::DOCUMENT_FRAGMENT_NODE:
                case DOMNode::NOTATION_NODE :
                default:
                        break;
                }
                cout << endl;
                if( cur->hasChildNodes() )
                        getChildren( cur, indent + 2 );
        }
  }
  catch (const xml_schema::exception& e)
  {
    cerr << "HELP ME    " << e << endl;
    return 1;
  }
}

Because the error is within /usr/local/xsd/libxsd/xsd/cxx/tree/types.hxx
I figured I'd contact you about it first though at the same time I am
wondering if it might be an issue with gcc or perhaps with my code. Any
help or advice would be greatly appreciated.

Thanks for your help in the past and in advance.

Pat




On Wed, 2006-11-01 at 19:37 +0200, Boris Kolpackov wrote:
> Hi Patrick,
> 
> Thanks for resending this to xsd-users.
> 
> Patrick Shinpaugh <pshinpaugh at adelphia.net> writes:
> 
> > I was actually wrong about the root element but the site was useful. I
> > have it working now except for one possible issue. I was expecting to be
> > able to pass a url to the root instantiation loader:
> >
> > auto_ptr<x3d::X3D> inst (x3d::X3D_ (argv[1], xml_schema::flags::keep_dom
> > | xml_schema::flags::dont_initialize, props ));
> >
> > However, it prepends the current working directory:
> >
> > ./x3d https://someserver/file.x3d
> > :0:0 error: An exception occurred! Type:RuntimeException, Message:The
> > primary document entity could not be opened.
> > Id=/home/patrick/projects/x3dosg/sample_implementation/code_synthesis_xsd/cxx-tree/https://someserver/file.x3d
> >
> > Any ideas what I may be doing wrong?
> 
> XSD does not support HTTPS protocol in URLs (HTTP and FTP are supported if
> you build Xerces-C++ with network enabled). You will need to use a third-
> party library for HTTPS. Libcurl[1] seems like a good candidate.
> 
> You can read the data using the third-party library and then present it
> to XSD as either std::istream or xercesc::InputSource. If the file is
> not very big you can also read it in as a string and then parse it using
> std::istringstream.
> 
> 
> [1] http://curl.haxx.se/libcurl/
> 
> 
> hth,
> -boris
-- 
Patrick Shinpaugh
Virginia Tech
UVAG System Administrator/Programmer
540-231-2054




More information about the xsd-users mailing list