You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Jerome Magnet <je...@nortel.com> on 2006/02/17 20:59:25 UTC

XML Beans usage question

I am trying to use XML beans in doing simple parsing and data retieval.
I successfully generated all the Java classes for two schemas. The parsing of 
an XML document built with these two embedded XML from two different namespaces 
seems to be working well. But, I can't retrieve the simple element values using 
the get methods. I was able to do it for a simple XML from one 
schema/namespace. Also, I noticed that it only works if you parse from the 
document class ("Element"Document.Factory.parse()). And, it does not work if 
you parse directly with the element class ("Element".Factory.parse()). I could 
not find out why in the user guides?

thanks to help identify the simple thing I am not seeing!
Here are the details below:

I use Win2000 with latest XML Beans 2.

The following is my code snipet:
File msgFile = new File(reqMsgDocFilename);
EnvelopeDocument soapEnvDoc = EnvelopeDocument.Factory.parse(msgFile);
Envelope soapEnv = soapEnvDoc.getEnvelope();
Header soapHdr = soapEnv.getHeader();
HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode());
System.out.println("\nRequest header fragment as Xbean toStr:\n"+hdrT.toString
());
System.out.println("hdrT.activity="+hdrT.getActivityName());

The following is the output from the above code:
Request header fragment as Xbean toStr:
<soap:Header xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns="tmf854.v1">
  <header>
    <activityName>getSNCsByUserLabel</activityName>
    <msgName>getSNCsByUserLabel</msgName>
    <msgType>REQUEST</msgType>
    <replyToURI>MTOSI/CramerOS</replyToURI>
    <correlationId>1234</correlationId>
    <communicationPattern>SimpleResponse</communicationPattern>
    <communicationStyle>MSG</communicationStyle>
    <timestamp>20051004140259</timestamp>
  </header>
</soap:Header>
hdrT.activity=null

Notice that I have two schemas 1:SOAP-ENV and 2:MyOwn (default namespace)
I can't get to any of the <header> element values (getActivityName returned 
null)

Here is my own schema
<?xml version="1.0" encoding="UTF-8"?>
<!-- TMF854 Version 1.0 - Copyright TeleManagement Forum 2005 -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
targetNamespace="tmf854.v1" xmlns="tmf854.v1" 
attributeFormDefault="unqualified" elementFormDefault="qualified">
  <!-- ======= All includes  ======= -->
  <xsd:include schemaLocation="headerVendorExtensions.xsd"/>
  <!-- ======== Global Type Declarations ========= -->
  <xsd:simpleType name="ActivityName_T">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\w*"/>
    </xsd:restriction>
  </xsd:simpleType>
...
  <xsd:element name="header" type="Header_T"/>
  <xsd:complexType name="Header_T">
    <xsd:all>
      <xsd:element name="activityName" type="ActivityName_T">
      </xsd:element>
...
  </xsd:complexType>
</xsd:schema>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: XML Beans usage question

Posted by Jerome Magnet <je...@nortel.com>.

Edward Frederick <epfrederick <at> gmail.com> writes:

> 
> You're close--I think there's two pieces to the problem.
> 
> On your dump of the soap header, the <cur> is the soap:Header and not
> your  header <at> tmf854.v1. So I think the steps to get it working are:
> 
> 1) get a hold of the header <at> tmf854.v1 node (does dumping
> getFirstChild() give you this as <cur>?)
> 
> 2) parse it with the HeaderT document factory.
> 
> HeaderTDocument encl = HeaderTDocument.Factory.parse(yourHeaderDomNode);
> HeaderT hdr = encl.getHeaderT();
> 
> Good Luck,
> 
> Ed
> 

Ed,

First, what is it with this error of top-posting? I have never such stupid 
thing!

Now the dump was with the original:

HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode());

If I do down one level by adding .getFirstChild() I get an empty dump as 
followed:

  ROOT Value( "\n\t\t" ) (USER) *:R:<cur>[0] (DocumentXobj)

And if I do as you mention below

File msgFile = new File(reqMsgDocFilename);
EnvelopeDocument soapEnvDoc = EnvelopeDocument.Factory.parse(msgFile);
Envelope soapEnv = soapEnvDoc.getEnvelope();
Header soapHdr = soapEnv.getHeader();
HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode().getFirstChild());
HeaderDocument hdrDoc = HeaderDocument.Factory.parse(soapHdr.getDomNode
().getFirstChild());
HeaderT hdr = hdrDoc.getHeader();
System.out.println("\nRequest header fragment as Xbean toStr:\n"+hdrDoc.toString
());
System.out.println("hdrT.activity="+hdr.getActivityName());
soapHdr.dump();
hdr.dump();

I get an exception:
org.apache.xmlbeans.XmlException: error: The document is not a 
header@tmf854.v1: no document element
	at org.apache.xmlbeans.impl.store.Locale.verifyDocumentType
(Locale.java:452)
	at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument
(Locale.java:357)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject
(Locale.java:1384)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject
(Locale.java:1363)
	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse
(SchemaTypeLoaderBase.java:370)
	at org.tmforum.mtosi.HeaderDocument$Factory.parse(Unknown Source)
	at Main.testXMLBeans(Main.java:65)
	at Main.main(Main.java:32)

Thanks,
Jerome




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: XML Beans usage question

Posted by Edward Frederick <ep...@gmail.com>.
You're close--I think there's two pieces to the problem.

On your dump of the soap header, the <cur> is the soap:Header and not
your  header@tmf854.v1. So I think the steps to get it working are:

1) get a hold of the header@tmf854.v1 node (does dumping
getFirstChild() give you this as <cur>?)

2) parse it with the HeaderT document factory.

HeaderTDocument encl = HeaderTDocument.Factory.parse(yourHeaderDomNode);
HeaderT hdr = encl.getHeaderT();


Good Luck,

Ed



On 2/17/06, Jerome Magnet <je...@nortel.com> wrote:
> Edward Frederick <epfrederick <at> gmail.com> writes:
>
> >
> > Jerome,
> >
> > Re: Using the *Document Factories: It's kind of a subtle thing, but
> > the compiled objects represent the -contents- of the types, not the
> > elements themselves. You need to use the document factory because
> > you're parsing a document that has an instance of a complex type as
> > its document element, not a document that represents the contents of
> > an instance of a complex type. I even confuse myself (if I'm not
> > already off base).
> >
> > My guess is that the header within a header thing is killing
> > you--hdrT's factory is parsing the entire soap header, not your header
> > within that header. They have the same name, so it looks like the
> > factory isn't complaining about the contour.
> >
> > Maybe try:
> >
> > HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode().getFirstChild());
> >
> > Ed
> >
> > On 2/17/06, Jerome Magnet <jeromem <at> nortel.com> wrote:
> > > I am trying to use XML beans in doing simple parsing and data retieval.
> > > I successfully generated all the Java classes for two schemas. The parsing
> of
> > > an XML document built with these two embedded XML from two different
> namespaces
> > > seems to be working well. But, I can't retrieve the simple element values
> using
> > > the get methods. I was able to do it for a simple XML from one
> > > schema/namespace. Also, I noticed that it only works if you parse from the
> > > document class ("Element"Document.Factory.parse()). And, it does not work if
> > > you parse directly with the element class ("Element".Factory.parse()). I
> could
> > > not find out why in the user guides?
> > >
> > > thanks to help identify the simple thing I am not seeing!
> > > Here are the details below:
> > >
> > > I use Win2000 with latest XML Beans 2.
> > >
> > > The following is my code snipet:
> > > File msgFile = new File(reqMsgDocFilename);
> > > EnvelopeDocument soapEnvDoc = EnvelopeDocument.Factory.parse(msgFile);
> > > Envelope soapEnv = soapEnvDoc.getEnvelope();
> > > Header soapHdr = soapEnv.getHeader();
> > > HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode());
> > > System.out.println("\nRequest header fragment as Xbean
> toStr:\n"+hdrT.toString
> > > ());
> > > System.out.println("hdrT.activity="+hdrT.getActivityName());
> > >
> > > The following is the output from the above code:
> > > Request header fragment as Xbean toStr:
> > > <soap:Header xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
> > > xmlns="tmf854.v1">
> > >   <header>
> > >     <activityName>getSNCsByUserLabel</activityName>
> > >     <msgName>getSNCsByUserLabel</msgName>
> > >     <msgType>REQUEST</msgType>
> > >     <replyToURI>MTOSI/CramerOS</replyToURI>
> > >     <correlationId>1234</correlationId>
> > >     <communicationPattern>SimpleResponse</communicationPattern>
> > >     <communicationStyle>MSG</communicationStyle>
> > >     <timestamp>20051004140259</timestamp>
> > >   </header>
> > > </soap:Header>
> > > hdrT.activity=null
> > >
> > > Notice that I have two schemas 1:SOAP-ENV and 2:MyOwn (default namespace)
> > > I can't get to any of the <header> element values (getActivityName returned
> > > null)
> > >
> > > Here is my own schema
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <!-- TMF854 Version 1.0 - Copyright TeleManagement Forum 2005 -->
> > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > > targetNamespace="tmf854.v1" xmlns="tmf854.v1"
> > > attributeFormDefault="unqualified" elementFormDefault="qualified">
> > >   <!-- ======= All includes  ======= -->
> > >   <xsd:include schemaLocation="headerVendorExtensions.xsd"/>
> > >   <!-- ======== Global Type Declarations ========= -->
> > >   <xsd:simpleType name="ActivityName_T">
> > >     <xsd:restriction base="xsd:string">
> > >       <xsd:pattern value="\w*"/>
> > >     </xsd:restriction>
> > >   </xsd:simpleType>
> > > ...
> > >   <xsd:element name="header" type="Header_T"/>
> > >   <xsd:complexType name="Header_T">
> > >     <xsd:all>
> > >       <xsd:element name="activityName" type="ActivityName_T">
> > >       </xsd:element>
> > > ...
> > >   </xsd:complexType>
> > > </xsd:schema>
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe <at> xmlbeans.apache.org
> > > For additional commands, e-mail: user-help <at> xmlbeans.apache.org
> > >
> > >
> >
>
> Ed,
>
> Thanks for following up on my stumbles using XML Beans.
> I tried your sugestion without luck. I spent a long time on this issue with XML
> Beans. I tried with the body part of my soap envelope, which is a complex of a
> single simple type element (string). There is no element name conflict as you
> mentioned, which does not really exists as from two namespaces; soap:Header and
> tmf854.v1@header. So, even with the soap:body element retrieval it does not
> work!
>
> I am very confused. It I do a dump of the two headers:.
> soapHdr.dump();
> hdrT.dump();
>
> I get the following:
>   ROOT (USER) <mark>[0] (DocumentXobj)
>     ELEM soap:Envelope@http://www.w3.org/2003/05/soap-envelope (USER)
> (ElementXobj)
>       ATTR xmlns:soap@http://www.w3.org/2000/xmlns/ Value
> ( "http://www.w3.org/2003/05/soap-envel..." ) (AttrXobj)
>       ATTR xmlns@http://www.w3.org/2000/xmlns/ Value( "tmf854.v1" ) After
> ( "\n\t" ) (AttrXobj)
>       ELEM soap:Header@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t"
> TEXT[3] ) (USER) After( "\n\t" TEXT[2] ) *:R:<cur>[0] (ElementXobj)
>         ELEM header@tmf854.v1 Value( "\n\t\t\t" TEXT[4] ) After( "\n\t" TEXT
> [2] ) (ElementXobj)
>           ELEM activityName@tmf854.v1 Value( "getSNCsByUserLabel" TEXT[18] )
> After( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM msgName@tmf854.v1 Value( "getSNCsByUserLabel" TEXT[18] ) After
> ( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM msgType@tmf854.v1 Value( "REQUEST" TEXT[7] ) After( "\n\t\t\t"
> TEXT[4] ) (ElementXobj)
>           ELEM replyToURI@tmf854.v1 Value( "MTOSI/CramerOS" TEXT[14] ) After
> ( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM correlationId@tmf854.v1 Value( "1234" TEXT[4] ) After
> ( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM communicationPattern@tmf854.v1 Value( "SimpleResponse" TEXT
> [14] ) After( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM communicationStyle@tmf854.v1 Value( "MSG" TEXT[3] ) After
> ( "\n\t\t\t" TEXT[4] ) (ElementXobj)
>           ELEM timestamp@tmf854.v1 Value( "20051004140259" TEXT[14] ) After
> ( "\n\t\t" TEXT[3] ) (ElementXobj)
>       ELEM soap:Body@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t" )
> After( "\n" ) (ElementXobj)
>         ELEM getSNCsByUserLabel@tmf854.v1 Value( "\n\t\t\t" ) After( "\n\t" )
> (ElementXobj)
>           ELEM userLabel@tmf854.v1 Value( "aUserLabel" ) After( "\n\t\t" )
> (ElementXobj)
>
>   ROOT (USER) *:R:<cur>[0] (DocumentXobj)
>     ELEM soap:Header@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t" )
> (ElementXobj)
>       ELEM header@tmf854.v1 Value( "\n\t\t\t" ) After( "\n\t" ) (ElementXobj)
>         ELEM activityName@tmf854.v1 Value( "getSNCsByUserLabel" ) After
> ( "\n\t\t\t" ) (ElementXobj)
>         ELEM msgName@tmf854.v1 Value( "getSNCsByUserLabel" ) After
> ( "\n\t\t\t" ) (ElementXobj)
>         ELEM msgType@tmf854.v1 Value( "REQUEST" ) After( "\n\t\t\t" )
> (ElementXobj)
>         ELEM replyToURI@tmf854.v1 Value( "MTOSI/CramerOS" ) After( "\n\t\t\t" )
> (ElementXobj)
>         ELEM correlationId@tmf854.v1 Value( "1234" ) After( "\n\t\t\t" )
> (ElementXobj)
>         ELEM communicationPattern@tmf854.v1 Value( "SimpleResponse" ) After
> ( "\n\t\t\t" ) (ElementXobj)
>         ELEM communicationStyle@tmf854.v1 Value( "MSG" ) After( "\n\t\t\t" )
> (ElementXobj)
>         ELEM timestamp@tmf854.v1 Value( "20051004140259" ) After( "\n\t\t" )
> (ElementXobj)
>
> So, it seems that the structure is all there. But, how can I access the
> <header> element values using the XML beans methods?
>
> Jerome
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: XML Beans usage question

Posted by Jerome Magnet <je...@nortel.com>.
Edward Frederick <epfrederick <at> gmail.com> writes:

> 
> Jerome,
> 
> Re: Using the *Document Factories: It's kind of a subtle thing, but
> the compiled objects represent the -contents- of the types, not the
> elements themselves. You need to use the document factory because
> you're parsing a document that has an instance of a complex type as
> its document element, not a document that represents the contents of
> an instance of a complex type. I even confuse myself (if I'm not
> already off base).
> 
> My guess is that the header within a header thing is killing
> you--hdrT's factory is parsing the entire soap header, not your header
> within that header. They have the same name, so it looks like the
> factory isn't complaining about the contour.
> 
> Maybe try:
> 
> HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode().getFirstChild());
> 
> Ed
> 
> On 2/17/06, Jerome Magnet <jeromem <at> nortel.com> wrote:
> > I am trying to use XML beans in doing simple parsing and data retieval.
> > I successfully generated all the Java classes for two schemas. The parsing 
of
> > an XML document built with these two embedded XML from two different 
namespaces
> > seems to be working well. But, I can't retrieve the simple element values 
using
> > the get methods. I was able to do it for a simple XML from one
> > schema/namespace. Also, I noticed that it only works if you parse from the
> > document class ("Element"Document.Factory.parse()). And, it does not work if
> > you parse directly with the element class ("Element".Factory.parse()). I 
could
> > not find out why in the user guides?
> >
> > thanks to help identify the simple thing I am not seeing!
> > Here are the details below:
> >
> > I use Win2000 with latest XML Beans 2.
> >
> > The following is my code snipet:
> > File msgFile = new File(reqMsgDocFilename);
> > EnvelopeDocument soapEnvDoc = EnvelopeDocument.Factory.parse(msgFile);
> > Envelope soapEnv = soapEnvDoc.getEnvelope();
> > Header soapHdr = soapEnv.getHeader();
> > HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode());
> > System.out.println("\nRequest header fragment as Xbean 
toStr:\n"+hdrT.toString
> > ());
> > System.out.println("hdrT.activity="+hdrT.getActivityName());
> >
> > The following is the output from the above code:
> > Request header fragment as Xbean toStr:
> > <soap:Header xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
> > xmlns="tmf854.v1">
> >   <header>
> >     <activityName>getSNCsByUserLabel</activityName>
> >     <msgName>getSNCsByUserLabel</msgName>
> >     <msgType>REQUEST</msgType>
> >     <replyToURI>MTOSI/CramerOS</replyToURI>
> >     <correlationId>1234</correlationId>
> >     <communicationPattern>SimpleResponse</communicationPattern>
> >     <communicationStyle>MSG</communicationStyle>
> >     <timestamp>20051004140259</timestamp>
> >   </header>
> > </soap:Header>
> > hdrT.activity=null
> >
> > Notice that I have two schemas 1:SOAP-ENV and 2:MyOwn (default namespace)
> > I can't get to any of the <header> element values (getActivityName returned
> > null)
> >
> > Here is my own schema
> > <?xml version="1.0" encoding="UTF-8"?>
> > <!-- TMF854 Version 1.0 - Copyright TeleManagement Forum 2005 -->
> > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > targetNamespace="tmf854.v1" xmlns="tmf854.v1"
> > attributeFormDefault="unqualified" elementFormDefault="qualified">
> >   <!-- ======= All includes  ======= -->
> >   <xsd:include schemaLocation="headerVendorExtensions.xsd"/>
> >   <!-- ======== Global Type Declarations ========= -->
> >   <xsd:simpleType name="ActivityName_T">
> >     <xsd:restriction base="xsd:string">
> >       <xsd:pattern value="\w*"/>
> >     </xsd:restriction>
> >   </xsd:simpleType>
> > ...
> >   <xsd:element name="header" type="Header_T"/>
> >   <xsd:complexType name="Header_T">
> >     <xsd:all>
> >       <xsd:element name="activityName" type="ActivityName_T">
> >       </xsd:element>
> > ...
> >   </xsd:complexType>
> > </xsd:schema>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe <at> xmlbeans.apache.org
> > For additional commands, e-mail: user-help <at> xmlbeans.apache.org
> >
> >
> 

Ed,

Thanks for following up on my stumbles using XML Beans.
I tried your sugestion without luck. I spent a long time on this issue with XML 
Beans. I tried with the body part of my soap envelope, which is a complex of a 
single simple type element (string). There is no element name conflict as you 
mentioned, which does not really exists as from two namespaces; soap:Header and 
tmf854.v1@header. So, even with the soap:body element retrieval it does not 
work!

I am very confused. It I do a dump of the two headers:.
soapHdr.dump();
hdrT.dump();

I get the following:
  ROOT (USER) <mark>[0] (DocumentXobj)
    ELEM soap:Envelope@http://www.w3.org/2003/05/soap-envelope (USER) 
(ElementXobj)
      ATTR xmlns:soap@http://www.w3.org/2000/xmlns/ Value
( "http://www.w3.org/2003/05/soap-envel..." ) (AttrXobj)
      ATTR xmlns@http://www.w3.org/2000/xmlns/ Value( "tmf854.v1" ) After
( "\n\t" ) (AttrXobj)
      ELEM soap:Header@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t" 
TEXT[3] ) (USER) After( "\n\t" TEXT[2] ) *:R:<cur>[0] (ElementXobj)
        ELEM header@tmf854.v1 Value( "\n\t\t\t" TEXT[4] ) After( "\n\t" TEXT
[2] ) (ElementXobj)
          ELEM activityName@tmf854.v1 Value( "getSNCsByUserLabel" TEXT[18] ) 
After( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM msgName@tmf854.v1 Value( "getSNCsByUserLabel" TEXT[18] ) After
( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM msgType@tmf854.v1 Value( "REQUEST" TEXT[7] ) After( "\n\t\t\t" 
TEXT[4] ) (ElementXobj)
          ELEM replyToURI@tmf854.v1 Value( "MTOSI/CramerOS" TEXT[14] ) After
( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM correlationId@tmf854.v1 Value( "1234" TEXT[4] ) After
( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM communicationPattern@tmf854.v1 Value( "SimpleResponse" TEXT
[14] ) After( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM communicationStyle@tmf854.v1 Value( "MSG" TEXT[3] ) After
( "\n\t\t\t" TEXT[4] ) (ElementXobj)
          ELEM timestamp@tmf854.v1 Value( "20051004140259" TEXT[14] ) After
( "\n\t\t" TEXT[3] ) (ElementXobj)
      ELEM soap:Body@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t" ) 
After( "\n" ) (ElementXobj)
        ELEM getSNCsByUserLabel@tmf854.v1 Value( "\n\t\t\t" ) After( "\n\t" ) 
(ElementXobj)
          ELEM userLabel@tmf854.v1 Value( "aUserLabel" ) After( "\n\t\t" ) 
(ElementXobj)

  ROOT (USER) *:R:<cur>[0] (DocumentXobj)
    ELEM soap:Header@http://www.w3.org/2003/05/soap-envelope Value( "\n\t\t" ) 
(ElementXobj)
      ELEM header@tmf854.v1 Value( "\n\t\t\t" ) After( "\n\t" ) (ElementXobj)
        ELEM activityName@tmf854.v1 Value( "getSNCsByUserLabel" ) After
( "\n\t\t\t" ) (ElementXobj)
        ELEM msgName@tmf854.v1 Value( "getSNCsByUserLabel" ) After
( "\n\t\t\t" ) (ElementXobj)
        ELEM msgType@tmf854.v1 Value( "REQUEST" ) After( "\n\t\t\t" ) 
(ElementXobj)
        ELEM replyToURI@tmf854.v1 Value( "MTOSI/CramerOS" ) After( "\n\t\t\t" ) 
(ElementXobj)
        ELEM correlationId@tmf854.v1 Value( "1234" ) After( "\n\t\t\t" ) 
(ElementXobj)
        ELEM communicationPattern@tmf854.v1 Value( "SimpleResponse" ) After
( "\n\t\t\t" ) (ElementXobj)
        ELEM communicationStyle@tmf854.v1 Value( "MSG" ) After( "\n\t\t\t" ) 
(ElementXobj)
        ELEM timestamp@tmf854.v1 Value( "20051004140259" ) After( "\n\t\t" ) 
(ElementXobj)

So, it seems that the structure is all there. But, how can I access the 
<header> element values using the XML beans methods?

Jerome





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: XML Beans usage question

Posted by Edward Frederick <ep...@gmail.com>.
Jerome,

Re: Using the *Document Factories: It's kind of a subtle thing, but
the compiled objects represent the -contents- of the types, not the
elements themselves. You need to use the document factory because
you're parsing a document that has an instance of a complex type as
its document element, not a document that represents the contents of
an instance of a complex type. I even confuse myself (if I'm not
already off base).

My guess is that the header within a header thing is killing
you--hdrT's factory is parsing the entire soap header, not your header
within that header. They have the same name, so it looks like the
factory isn't complaining about the contour.

Maybe try:

HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode().getFirstChild());

Ed






On 2/17/06, Jerome Magnet <je...@nortel.com> wrote:
> I am trying to use XML beans in doing simple parsing and data retieval.
> I successfully generated all the Java classes for two schemas. The parsing of
> an XML document built with these two embedded XML from two different namespaces
> seems to be working well. But, I can't retrieve the simple element values using
> the get methods. I was able to do it for a simple XML from one
> schema/namespace. Also, I noticed that it only works if you parse from the
> document class ("Element"Document.Factory.parse()). And, it does not work if
> you parse directly with the element class ("Element".Factory.parse()). I could
> not find out why in the user guides?
>
> thanks to help identify the simple thing I am not seeing!
> Here are the details below:
>
> I use Win2000 with latest XML Beans 2.
>
> The following is my code snipet:
> File msgFile = new File(reqMsgDocFilename);
> EnvelopeDocument soapEnvDoc = EnvelopeDocument.Factory.parse(msgFile);
> Envelope soapEnv = soapEnvDoc.getEnvelope();
> Header soapHdr = soapEnv.getHeader();
> HeaderT hdrT = HeaderT.Factory.parse(soapHdr.getDomNode());
> System.out.println("\nRequest header fragment as Xbean toStr:\n"+hdrT.toString
> ());
> System.out.println("hdrT.activity="+hdrT.getActivityName());
>
> The following is the output from the above code:
> Request header fragment as Xbean toStr:
> <soap:Header xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
> xmlns="tmf854.v1">
>   <header>
>     <activityName>getSNCsByUserLabel</activityName>
>     <msgName>getSNCsByUserLabel</msgName>
>     <msgType>REQUEST</msgType>
>     <replyToURI>MTOSI/CramerOS</replyToURI>
>     <correlationId>1234</correlationId>
>     <communicationPattern>SimpleResponse</communicationPattern>
>     <communicationStyle>MSG</communicationStyle>
>     <timestamp>20051004140259</timestamp>
>   </header>
> </soap:Header>
> hdrT.activity=null
>
> Notice that I have two schemas 1:SOAP-ENV and 2:MyOwn (default namespace)
> I can't get to any of the <header> element values (getActivityName returned
> null)
>
> Here is my own schema
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- TMF854 Version 1.0 - Copyright TeleManagement Forum 2005 -->
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="tmf854.v1" xmlns="tmf854.v1"
> attributeFormDefault="unqualified" elementFormDefault="qualified">
>   <!-- ======= All includes  ======= -->
>   <xsd:include schemaLocation="headerVendorExtensions.xsd"/>
>   <!-- ======== Global Type Declarations ========= -->
>   <xsd:simpleType name="ActivityName_T">
>     <xsd:restriction base="xsd:string">
>       <xsd:pattern value="\w*"/>
>     </xsd:restriction>
>   </xsd:simpleType>
> ...
>   <xsd:element name="header" type="Header_T"/>
>   <xsd:complexType name="Header_T">
>     <xsd:all>
>       <xsd:element name="activityName" type="ActivityName_T">
>       </xsd:element>
> ...
>   </xsd:complexType>
> </xsd:schema>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org