none
XPathMutatorStream and DisallowedNodeException RRS feed

  • Question

  • Hi all,

    I have these 2 xml documents and the 1st one instantiates the XmlTextReader and the 2nd raises a DisallowedNodeException. The only difference is the LOC node has child elements in the 2nd one and the 1st doesnt. Can anyone see what is wrong here?

     

    <ns1:UNB Id="EC7ED3F6DC334A1B980A7768148979BA" MessageType="44" BuyerAppleId="295183" xmlns:ns1="http://Australia.Integration.TradingPartner.Apple.Schemas.SLSRPT.Transfer">
      <BeginDate xmlns="">20080920</BeginDate>
      <EndDate xmlns="">20080921</EndDate>
      <ReportDate xmlns="">20080921</ReportDate>
      <UNH Id="3C2CD007B7A042F2ACC8BFCDF21F9CE4" xmlns="">
       <LOC/>
      </UNH>
      <UNH Id="3C2CD007B7A042F2ACC8BFCDF21F9CE4" xmlns="">
       <LOC/>
      </UNH>
     </ns1:UNB>

     

    <ns1:UNB Id="E2E1AEB7D26C49A79ABC5C274B432138" MessageType="190" BuyerAppleId="302201" xmlns:ns1="http://Australia.Integration.TradingPartner.Apple.Schemas.SLSRPT.SellThru">
      <BeginDate xmlns="">20080921</BeginDate>
      <EndDate xmlns="">20080922</EndDate>
      <ReportDate xmlns="">20080922</ReportDate>
      <UNH Id="AB34B3B7EDC649B5B17E343B22976E30" xmlns="">
       <LOC>
        <StoreID>A337</StoreID>
        <LIN>
         <AppleMarketingPartNo>XIPHONE8GBLK</AppleMarketingPartNo>
         <InvoiceNumber>A762695</InvoiceNumber>
         <InvoiceDate>20080920</InvoiceDate>
         <QtySold>1</QtySold>
         <GIN>
          <Serials>011613003747463</Serials>
         </GIN>
        </LIN>
       </LOC>
      </UNH>
      
     </ns1:UNB>

     

    XPathCollection queries = new XPathCollection();

     

    queries.Add(new XPathExpression("/*[local-name()='UNB' and namespace-uri()='http://Australia.Integration.TradingPartner.Apple.Schemas.SLSRPT.SellThru']/*[local-name()='UNH' and namespace-uri()='']/*[local-name()='LOC' and namespace-uri()='']"));


    ValueMutator mutator = new ValueMutator(this.XPathCallBack);

    XPathMutatorStream mutatorStream = new XPathMutatorStream(pInMsg.BodyPart.GetOriginalDataStream(), queries, mutator);
               

    XmlTextReader reader = new XmlTextReader(mutatorStream); //DISALLOWEDNODES EXCEPTION RAISED HERE
               

    while (reader.Read()) ;

    Wednesday, September 24, 2008 10:24 PM

Answers

  • Hi Jodi,

     

    I had a look in the DLL and inside the TranslateElement method of XPathMutatorStream is where your exception is thrown:

     

    Code Snippet

    if (XmlNodeType.EndElement == reader.NodeType)

    {

    this._mutateAndEndElement(this._elemMatches, builder.ToString());

    }

    else

    {

    XmlNodeType nodeType = reader.NodeType;

    if (((XmlNodeType.Text != nodeType) && (XmlNodeType.CDATA != nodeType)) && ((XmlNodeType.SignificantWhitespace != nodeType) && (XmlNodeType.Whitespace != nodeType)))

    {

    throw new DisallowedNodeException(reader.NodeType);

    }

    builder.Append(reader.Value);

    }

     

     


    It does look like it needs to match a node or element with text, CDATA or whitespace, did you change your xpath to StoreID?

    Thursday, September 25, 2008 9:07 PM

All replies

  •  

    Hi Jody,

     

    What is the element that you actually want to update? I think your xpath expression should be on the specific element that will be updated, for example, for StoreID:

     

    /*[local-name()='UNB' and namespace-uri()='http://Australia.Integration.TradingPartner.Apple.Schemas.SLSRPT.SellThru']/*[local-name()='UNH' and namespace-uri()='']/*[local-name()='LOC' and namespace-uri()='']/*[local-name()='StoreID' and namespace-uri()='']

     

    Also I noticed that the namespace between the two sample XML are different (one is Transfer and the other is SellThru), not sure if you're changing your xpath expression depending on the different namespace.

     

    Regards,

                   Thiago Almeida

                   http://connectedthoughts.wordpress.com

     

    Thursday, September 25, 2008 12:20 AM
  • Thanks Thiago,

    The namespace is just a typo (they are the same I just copied the wrong one!!).

     

    What I was trying to achieve was in the callback I was just trying to detect whether the LOC node was present if it want I was just going to return a null message to the message box. I didnt want to load it into a XmlDocument as I wanted to try and use a streaming approach.

     

    *****From the Execute  Method****

    if (!bMatch)
           return null;
    else
    {
           return pInMsg;
    }

     

    private void XPathCallBack(int matchIdx, XPathExpression matchExpr, string origVal, ref string finalVal)
    {

        bMatch = true;
    }

     

    From you post it sounds like the node in the xpath cant contain other nodes! is this what your suggesting?

     

    thanks

     

    Thursday, September 25, 2008 5:43 AM
  • Hi Jodi,

     

    I had a look in the DLL and inside the TranslateElement method of XPathMutatorStream is where your exception is thrown:

     

    Code Snippet

    if (XmlNodeType.EndElement == reader.NodeType)

    {

    this._mutateAndEndElement(this._elemMatches, builder.ToString());

    }

    else

    {

    XmlNodeType nodeType = reader.NodeType;

    if (((XmlNodeType.Text != nodeType) && (XmlNodeType.CDATA != nodeType)) && ((XmlNodeType.SignificantWhitespace != nodeType) && (XmlNodeType.Whitespace != nodeType)))

    {

    throw new DisallowedNodeException(reader.NodeType);

    }

    builder.Append(reader.Value);

    }

     

     


    It does look like it needs to match a node or element with text, CDATA or whitespace, did you change your xpath to StoreID?

    Thursday, September 25, 2008 9:07 PM
  • Yeh that did the trick...thanks

     

    question though - I am using .NET Reflector and I was wondering how you worked out that the TranslateElement method was causing the problem when

    XmlTextReader reader = new XmlTextReader(mutatorStream);

    raised the exception. I couldnt figure out where the TranslateElement method was being called!

     

    Thanks

    Thursday, September 25, 2008 11:26 PM
  •  

    I'm glad it's now working!

    In Reflector if you right click on the DisallowedNodeException class and select Analyze it'll show you who it's used by, and the only method using it is the TranslateElement.

     

    Thursday, September 25, 2008 11:38 PM
  • fantastic...I only use Reflector on the odd occassion but its good to know

     

    Friday, September 26, 2008 12:39 AM