Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on 

xml, jquery, complex

In jquery, is it possible to find element then get the rest of the nodes(outside of original element)?
E.g.

If i pass you BondName = abc and if it is found, then output me everything within <additionalInformation>?

 <Surety>
  <SuretyLine>
   
    <Commercial>
      <Bond>
		<General Information>
		<BondName>abc</BondName>
   		</General Information>
		<AddtionalInformation>
          		<div class="col-lg-12">
           		 <Input Type="text" Name="additionalInfo_licenseNo" ID="additionalInfo_licenseNo" Onchange="fnSaveSingleData(this.name,'1')" Placeholder="Enter License No." 				Class="form-control" Title="License is required!" PrefillValue="No" Required="" />
          		</div>

        	</AddtionalInformation>
      </Bond>
       <Bond>
	<General Information>
		<BondName>xyz</BondName>
   	</General Information>
	<AddtionalInformation>
          <div class="col-lg-12">
            <Input Type="text" Name="additionalInfo_licenseNo" ID="additionalInfo_licenseNo" Onchange="fnSaveSingleData(this.name,'1')" Placeholder="Enter License No." Class="form-control" 		Title="License is required!" PrefillValue="No" Required="" />
          </div>
        </AddtionalInformation>
      </Bond>
    </Commercial>
  </SuretyLine>
</Surety>

Open in new window

XMLjQueryREST

Avatar of undefined
Last Comment
Julian Hansen
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Since you have jQuery as one of the topic areas, you can try using .siblings() - https://api.jquery.com/siblings/
Avatar of ITsolutionWizard

ASKER

??? I have no idea what you mean. Please show me the codes to demo. Thanks
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

The code examples in the API documentation didn't make sense?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of leakim971
leakim971
Flag of Guadeloupe image

One more time, we already answered this very simple question in your previous posts.
If you don't go forward on your previous questiond I, personaly :), don't see any interest to ask the same question using a new formulation
I would be happy to discuss with you if you're not agree about this.
You let question opened.
And yes, you asked the same question.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

If element  contains the node for ABC then you can do
element.parent().find('.AddtionalInformation');

Open in new window

Avatar of ITsolutionWizard

ASKER

I try below. and not working. any ideas?

<script> 
function fnGetBondAdditionalInformation() {
    $.ajax({
        url: "http://localhost:5489/BondList.xml",
        success: function (xml) {
            parseSelectXMLBondAdditionalInformation(xml, "test", localStorage.getItem('bondState'), localStorage.getItem('bondName'))
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("Status: " + xhr.status);
            alert("Error: " + thrownError);
        }
    });
}
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
    var html = "";
    $(xml).find('Bond').each(function (i, e) {
        {
            if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {
                var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
                var selectedAdditionalInforation = $(e).find('AddtionalInformation').find('div').find('Input').text();
                $('#test').text(selectedAdditionalInforation);                  
              }
        }
    });
//    alert(html);
} 
window.onload = function () {
    fnGetBondAdditionalInformation();
}; 
</script>
<script>
     
</script>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

Share a link to your page so we can check your page online
Avatar of ITsolutionWizard

ASKER

That is all i have below

<script> 
function fnGetBondAdditionalInformation() {
    $.ajax({
        url: "http://localhost:5489/BondList.xml",
        success: function (xml) {
            parseSelectXMLBondAdditionalInformation(xml, "test", localStorage.getItem('bondState'), localStorage.getItem('bondName'))
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("Status: " + xhr.status);
            alert("Error: " + thrownError);
        }
    });
}
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
    var html = "";
    $(xml).find('Bond').each(function (i, e) {
        {
            if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {
                var selectedBondName = $(e).find('GeneralInformation').find('Name').text();
                var selectedAdditionalInforation = $(e).find('AddtionalInformation').find('div').find('Input').text();
                $('#test').text(selectedAdditionalInforation);                  
              }
        }
    });
//    alert(html);
} 
window.onload = function () {
    fnGetBondAdditionalInformation();
}; 
</script>
<p id="test"></p>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

Where to test it ?
Avatar of ITsolutionWizard

ASKER

U can just copy and paste the codes...
Avatar of leakim971
leakim971
Flag of Guadeloupe image

I would like to test it in your environment, not mine because if I say it work on my side, we blocked !
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Look at this line of code

function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName)

Open in new window

Now look at this line of code
if (bondState == $(e).find('GeneralInformation').find('State').text() && bondName == $(e).find('GeneralInformation').find('Name').text()) {

Open in new window

Now look at your GeneralInformaion block in your XML
<General Information>
  <BondName>abc</BondName>
</General Information>

Open in new window

There is no State value in your XML

Please advise - either post XML with valid data or explain what it is you want do because your code does not match your data.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Having looked at your code there are a number of other issues you need to look at.
1. You have invalid tags in your XML General Information has spaces in the name - this is not valid XML the element becomes General with an empty attribute Information
2. You are then searching for the text() of an Input - an Input does not have a text component.

The code below is sort of going in the direction of what you want - but you need to tell us
a) What your data looks like - the XML you have posted is incomplete and invalid
b) What data you want from the XML

How to get the value of AdditionaInformation based on selected BondName
function parseSelectXMLBondAdditionalInformation(xml, selectid, bondState, bondName) {
    var html = "";
    $(xml).find('Bond').each(function (i, e) {
        {
            var gi = $(e).find('GeneralInformation');;
			if (gi.find('BondName').text() == bondName) {
				var ai = gi.parent().find('AddtionalInformation');
				var text = ai.find('div > Input');//.text();
				// THIS OUTPUTS AN EMPTY STRING BECAUSE input ELEMENTS 
				// DON'T HAVE A text PORTION
				console.log(text);
			}
        }
    });
//    alert(html);
} 

Open in new window

Avatar of ITsolutionWizard

ASKER

Below is the data i want on html append

<div class="col-lg-12">
            <Input Type="text" Name="additionalInfo_licenseNo" ID="additionalInfo_licenseNo" Onchange="fnSaveSingleData(this.name,'1')" Placeholder="Enter License No." Class="form-control"             Title="License is required!" PrefillValue="No" Required="" />
          </div>
Avatar of ITsolutionWizard

ASKER

any helps?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

You have not answered the issues I raised in my earlier post. For me to help you you need to work with me.

There are errors in your XML and your code which tells me you have not given us everything we need to see. I cannot give you a solution without understanding the problem space - you need to address the issues I raised in my previous post.
Avatar of ITsolutionWizard

ASKER

what is your question? I think i already answered them. Thanks
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

1. You have invalid tags in your XML General Information has spaces in the name - this is not valid XML the element becomes General with an empty attribute Information

2. You are then searching for the text() of an Input - an Input does not have a text component.
XML
XML

Extensible Markup Language (XML) refers to the encoding of documents such that they can be read by both machines and humans. XML documents use tags to show the beginning and end of a set of data. XML is used extensively on websites to show volumes of data, and is the default for a number of office productivity suites. This topic includes discussions of XML-related technologies, such as XQuery (the XML Query language), XPath (the XML Path language), XSLT (eXtensible Stylesheet Language Transformations), XLink (the XML Linking language) and XPointer (the XML Pointer language).

22K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo